I read up on all the posts I could find and am still getting a nil URL when launching the app for the first time after tapping a dynamic link pasted into the Notes app on iOS. Actually I followed the video:
https://www.youtube.com/watch?v=sFPo296OQqk
Universal Links work fine and as expected through application(_:continue:restorationHandler:)
.
When coming through application(_:open:options:)
(formerly application:openURL:options:
) however, the URL comes in as <my-scheme-name>://google/link/?is_weak_match=1
. No matter how I configure my project/app, the URL is always nil. Also, application(_:open:options:)
is called on every first launch of the app regardless of whether a dynamic link was tapped before the app was installed or not. Is that to be expected?
Configuration:
- apple-app-site-association file is set up and looks good for Universal Links.
- Custom URL scheme set up in Info.plist.
- Using latest GoogleService-Info.plist
- Not in Safari 'Private' Mode
Calling in
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]; }
Setup:
- Xcode 8.3
- Deployment target: iOS 10.3.3
- Objective-C