【发布时间】:2017-08-25 04:30:59
【问题描述】:
我阅读了所有我能找到的帖子,并且在点击粘贴到 iOS 上的 Notes 应用程序中的动态链接后首次启动应用程序时仍然得到一个 nil URL。其实我是跟着视频看的:
https://www.youtube.com/watch?v=sFPo296OQqk
通过application(_:continue:restorationHandler:),Universal Links 可以正常工作并且符合预期。
但是,当通过application(_:open:options:)(以前的application:openURL:options:)进入时,URL 以<my-scheme-name>://google/link/?is_weak_match=1 的形式出现。无论我如何配置我的项目/应用程序,URL 始终为零。此外,每次首次启动应用时都会调用application(_:open:options:),无论是否在安装应用之前点击了动态链接。这是意料之中的吗?
配置:
- apple-app-site-association 文件已设置好,适合通用链接。
- 在 Info.plist 中设置了自定义 URL 方案。
- 使用最新的 GoogleService-Info.plist
- 不在 Safari 的“私人”模式下
-
拨打
didFinishLaunchingWithOptions[FIROptions defaultOptions].deepLinkURLScheme = CUSTOM_URL_SCHEME; [FIRApp configure]; - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { FIRDynamicLink *dynamicLink = [[FIRDynamicLinks dynamicLinks dynamicLinkFromCustomSchemeURL:url]; if (dynamicLink) { // Handle the deep link. For example, show the deep-linked content or // apply a promotional offer to the user's account. // [START_EXCLUDE] // In this sample, we just open an alert. NSString *message = [self generateDynamicLinkMessage:dynamicLink]; [self showDeepLinkAlertViewWithMessage:message]; // [END_EXCLUDE] return YES; } // [START_EXCLUDE silent] // Show the deep link that the app was called with. [self showDeepLinkAlertViewWithMessage:[NSString stringWithFormat:@"openURL:\n%@", url]]; // [END_EXCLUDE] return NO; } // [END openurl] // [START continueuseractivity] - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *))restorationHandler { // [START_EXCLUDE silent] NSLog(@"%@", userActivity.webpageURL); __weak AppDelegate *weakSelf = self; // [END_EXCLUDE] BOOL handled = [[FIRDynamicLinks dynamicLinks] handleUniversalLink:userActivity.webpageURL completion:^(FIRDynamicLink * _Nullable dynamicLink, NSError * _Nullable error) { // [START_EXCLUDE] AppDelegate *strongSelf = weakSelf; NSString *message = [strongSelf generateDynamicLinkMessage:dynamicLink]; [strongSelf showDeepLinkAlertViewWithMessage:message]; // [END_EXCLUDE] }]; // [START_EXCLUDE silent] if (!handled) { // Show the deep link URL from userActivity. NSString *message = [NSString stringWithFormat:@"continueUserActivity webPageURL:\n%@", userActivity.webpageURL]; [self showDeepLinkAlertViewWithMessage:message]; } // [END_EXCLUDE] return handled; } // [END continueuseractivity] - (NSString *)generateDynamicLinkMessage:(FIRDynamicLink *)dynamicLink { NSString *matchConfidence; if (dynamicLink.matchConfidence == FIRDynamicLinkMatchConfidenceStrong) { matchConfidence = @"strong"; } else { matchConfidence = @"weak"; } NSString *msg = [NSString stringWithFormat:@"App URL: %@\n" @"Match Confidence: %@\n", dynamicLink.url, matchConfidence]; return msg; } - (void)showDeepLinkAlertViewWithMessage:(NSString *)message { UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { NSLog(@"OK"); }]; UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Deep-link Data" message:message preferredStyle:UIAlertControllerStyleAlert]; [alertController addAction:okAction]; [self.window.rootViewController presentViewController:alertController animated:YES completion:nil]; }
设置:
- Xcode 8.3
- 部署目标:iOS 10.3.3
- Objective-C
【问题讨论】:
-
在您处理过的 AppDelegate 中显示您的代码。
-
我已经编辑了详细信息@JitendraSolanki
-
你在 didFinshLaunchingOptions 中返回了什么?
-
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [FIROptions defaultOptions].deepLinkURLScheme = CUSTOM_URL_SCHEME; [FIRApp 配置];返回是; }
-
您能否检查动态链接本身是否正常 - 在浏览器末尾附加 &d=1 应该会给您一个调试视图。
标签: ios objective-c firebase firebase-dynamic-links