OGeek|极客世界-中国程序员成长平台

标题: ios - Firebase 动态链接无法直接打开应用 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 14:12
标题: ios - Firebase 动态链接无法直接打开应用

根据 Firebase 文档,我在 Firebase 控制台中创建动态链接,然后在我的应用中包含动态链接 SDK。

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

但我点击备忘录中的链接,它会打开我的应用程序并直接转到正确的页面。我希望以同样的方式处理共享链接。

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

Appdelegate.m

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

- (BOOL)applicationUIApplication *)application continueUserActivitynonnull NSUserActivity *)userActivity restorationHandlernonnull 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;
}

ProductView.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 URLWithStringriginalLink];
    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];
    }];
}



Best Answer-推荐答案


你说的页面是App预览页面,见https://firebase.google.com/docs/dynamic-links/link-previews .

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

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

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

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];

你应该使用你的深层链接,像这样:

NSString *originalLink = [NSString stringWithFormat"https://levooya.com/product?product_id=%u", productID];

关于ios - Firebase 动态链接无法直接打开应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47687111/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4