9

According to the Firebase Dynamic Links documentation, even if app is not installed, if user opens the link on the device, app page on Appstore opened, and once app installed, application handles the link on the first launch. After some investigation how this handles, I found that Firebase has something called "pending dynamic links", and it is expected, that AppDelegate method is called with these links:

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options

The source of this assumption: https://groups.google.com/forum/#!msg/firebase-talk/2STD8eIi61I/8KJqZN7TBAAJ

But when I try to test this "pending dynamic lynks" feature, neither of these two AppDelegate methods been called

-(BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *))restorationHandler
-(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options

At the same time, if app installed, dynamic links work as expected, opening through the openURL: method if opened from gmail app through Chrome, through Universal links on iOS9 and later if opened from Notes or Mail app (through Safari actually).

So, my question is: How the "pending dynamic links" are expecting to work? What could be the reason my app doesn't handle them?

----------------EDIT----------------

The problem was, that by default Firebase tries to open the app with URL scheme which equals to the app bundle ID, which was not my case. I have changed my configuration of Firebase to the next:

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info" ofType:@"plist"];
FIROptions *options = [[FIROptions alloc] initWithContentsOfFile:filePath];
options.deepLinkURLScheme = @"MY-CUSTOM-SCHEME";
[FIRApp configureWithOptions:options];

And it start working, e.g. openURL: method is called now on the very first app open if link was opened on the device before.

2 Answers2

8

The post-install deeplinking is based on checking a flag:

  • [FIRApp configure] called
  • Dynamic Links SDK checks whether it is a fresh install (e.g. no flag present)
  • If so, it calls the Dynamic Links API to check if there is a dynamic link to resolve
  • If yes, the SDK calls [[UIApplication sharedApplication] openURL:url]; using the custom URL scheme set up manually on FIROptions or the lowercase bundle ID (e.g. com.foo.bar).

If you're not receiving, check the custom URL scheme is properly defined.

Ian Barber
  • 19,765
  • 3
  • 58
  • 58
  • 4
    Thank you, @ian-barber, for explanation. I have set `deepLinkURLScheme` property of `FIROptions`, and it start working. If you are Firebase team member, it's definitely worth to add these notes to the DynamicLinks doc. – Olexandr Stepanov Oct 20 '16 at 07:47
  • @OlexandrStepanov I have the same problem, I think that I set my deepLinkURLSchemes as needed : FIROptions.default().deepLinkURLScheme = "com.foo.boo" FIRApp.configure() Can u explain how do you manage to simulate an app first installation with xcode? – jerem Jan 04 '17 at 14:29
  • The doc is updated ! Thx. You could make it more clear by setting : FIROptions.default().deepLinkURLScheme = Bundle.main.bundleIdentifier – CedricSoubrie Apr 13 '17 at 09:18
0

To clarify, if my understanding of the linked Google Groups post is correct, the Firebase Dynamic Links library only checks for 'pending dynamic links' once. Ever. So if the app has already checked for pending links, you'd need to delete it and reinstall to check again.

Now to answer your question, neither of those two methods would usually be called if the app isn't installed when the link is clicked. The openURL method responds to custom URI schemes, and the continueUserActivity method responds to Universal Links. Neither of those is being used when the app is manually opened by the user after downloading for the first time. The Firebase documentation does say the openURL method always called on initial install, but I have never seen happening anywhere else so it's possible they are doing something unusual.

At risk of going off-topic, I'd suggest taking a look at Branch.io (full disclosure: I'm on the team). You'll get all of the benefits of Dynamic Links, plus a laundry list of extra functionality and clearer documentation :)

Alex Bauer
  • 13,147
  • 1
  • 27
  • 44
  • Thanks @AlexBauer, I would consider using Branch.io. But following my question, you said "the Firebase Dynamic Links library only checks for 'pending dynamic links' once". Ok, they check, but how the app can get knowing about these "pending dynamic links", that they actually exist for this first-time launch? Did you ever get these "pending dynamic links" working in your experience with Firebase DL? If yes, then how? – Olexandr Stepanov Sep 26 '16 at 09:43
  • 'Pending dynamic link' isn't actually used anywhere by the Firebase team. The discussion thread used it to indicate the concept of 'a link that the user has opened prior to installing the app for the first time'. This is all handled behind the scenes, so all you _should_ need to care about is that you get the same return whether or not the app is already installed. Of course you aren't currently, which is the issue! Looks like there is *another* `- (BOOL)application:(UIApplication *)application` method in the docs that might be just for new installs — do you have both set up? – Alex Bauer Sep 26 '16 at 21:04
  • Yes, I've definitely set up both application delegate methods, and I can see that each of them called under different circumstances: `openURL` when opened link from Chrome, `continueUserActivity` when opened from Safari, both on iOS9. But neither method is called after fresh install. Just to be precise, the steps are: deinstall app from the device, open dynamic link on the device, it opens the url inside `link` parameter, install app from XCode and run with breakpoints in both app delegate methods -> neither of methods called. So, do you believe it's a bug in Firebase? – Olexandr Stepanov Sep 28 '16 at 14:52
  • There appear to be three delegate methods, not two. Do you have the second `openURL` one in place? – Alex Bauer Sep 28 '16 at 19:02