Firebase Dynamic Link can’t open app directly

Nik*_*Lyu 4 objective-c dynamic-linking ios firebase firebase-dynamic-links

According to Firebase document, I create Dynamic Link in Firebase console, then include the Dynamic Links SDK in my app.

一切都很好,但是当我从 facebook 或 messenger 单击共享链接(这是我的动态链接)时,它会弹出一个带有打开应用程序按钮的页面,并询问我是否要打开我的应用程序。 在此处输入图片说明 我没有制作这个页面。我想删除这个。 在此处输入图片说明

但是我点击备忘录中的链接,它打开我的应用程序并直接转到正确的页面。我想要与共享链接相同的方式。

这是我的代码,我使用 Xcode 和 Objective-c 来开发 iOS 应用程序。谢谢!

Appdelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{   
    [FIROptions defaultOptions].deepLinkURLScheme = @"com.levooya.LeVooya";
    [FIRApp configure];
    return YES;
}

- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray * _Nullable))restorationHandler{
    NSURL *url = userActivity.webpageURL;
    NSLog(@"continueUserActivity url.absoluteString:%@",url.absoluteString);

    BOOL handled = [[FIRDynamicLinks dynamicLinks] handleUniversalLink:userActivity.webpageURL completion:^(FIRDynamicLink *dynamicLink, NSError *error){
        if(dynamicLink.url){
            NSLog(@"okokokokokok");
            NSLog(@"dynamicLink.url:%@",dynamicLink.url);

            NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:dynamicLink.url
                                                      resolvingAgainstBaseURL:NO];

            for(NSURLQueryItem *item in urlComponents.queryItems){
                if([item.name isEqualToString:@"product_id"]){
                    NSLog(@"item.value:%@",item.value);
                    NSString *productID = item.value;

                    NSDictionary *urlSchemeDict = [[NSDictionary alloc] init];

                    urlSchemeDict = [NSDictionary dictionaryWithObject:productID forKey:@"product_id"];
                    [[NSNotificationCenter defaultCenter] postNotificationName:@"URLSchemeShowProduct" object:nil userInfo:urlSchemeDict];

                    leData = [LevooyaData getInstance];
                    leData.urlSchemeDict = nil;
                    leData.urlSchemeDict = urlSchemeDict;
                }
            }
        }
    }];
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

产品视图.m

(这是我的应用中展示产品的页面,这里是我点击分享按钮生成动态链接的功能。)

- (void)share{
    NSString *originalLink = [NSString stringWithFormat:@"https://pbu3y.app.goo.gl/?link=https://levooya.com/product?product_id=%u&isi=1221262097&ibi=com.levooya.LeVooya&product_id=%u", productID, productID];
    NSURL *link = [NSURL URLWithString:originalLink];
    FIRDynamicLinkComponents *components =
    [FIRDynamicLinkComponents componentsWithLink:link
                                          domain:@"pbu3y.app.goo.gl"];

    FIRDynamicLinkSocialMetaTagParameters *socialParams = [FIRDynamicLinkSocialMetaTagParameters parameters];
    socialParams.title = product.brand;
    socialParams.descriptionText = product.product;
    components.socialMetaTagParameters = socialParams;

    FIRDynamicLinkNavigationInfoParameters *navigationInfoParameters = [FIRDynamicLinkNavigationInfoParameters parameters];
    navigationInfoParameters.forcedRedirectEnabled = 0;
    components.navigationInfoParameters = navigationInfoParameters;

    [components shortenWithCompletion:^(NSURL *_Nullable shortURL,
                                        NSArray *_Nullable warnings,
                                        NSError *_Nullable error) {
        // Handle shortURL or error.
        if (error) {
            NSLog(@"Error generating short link: %@", error.description);
            return;
        }
        shortenURL = shortURL;

        NSString *noteStr = [NSString stringWithFormat:NSLocalizedString(@"Check out %@ %@ on Levooya ! %@", nil), product.brand, product.product, shortenURL];
        UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:@[noteStr] applicationActivities:nil];
        [self presentViewController:activityVC animated:YES completion:nil];
    }];
}
Run Code Online (Sandbox Code Playgroud)

Ole*_*nov 8

您提到的页面是应用预览页面,请参阅https://firebase.google.com/docs/dynamic-links/link-previews

您可以通过指定动态链接参数来禁用此页面efr=1。在控制台中创建链接时也有一个复选框以禁用此页面。在您的代码中使用navigationInfoParameters.forcedRedirectEnabled = YES;.

需要记住的一点:如果您在 iPhone 上安装了应用程序时看到了应用程序预览页面,这意味着通用链接无法参与。将动态链接粘贴到浏览器地址栏时可能会发生这种情况。或者点击非合作应用程序内发生的链接(某些应用程序不允许使用通用链接)。确保您在禁用 App 预览的情况下测试了链接行为并且对此感到满意。

编辑:刚刚意识到您的深层链接不正确。代替

NSString *originalLink = [NSString stringWithFormat:@"https://pbu3y.app.goo.gl/?link=https://levooya.com/product?product_id=%u&isi=1221262097&ibi=com.levooya.LeVooya&product_id=%u", productID, productID];
Run Code Online (Sandbox Code Playgroud)

您应该使用深层链接,如下所示:

NSString *originalLink = [NSString stringWithFormat:@"https://levooya.com/product?product_id=%u", productID];
Run Code Online (Sandbox Code Playgroud)