2

I am implementing firebase dynamic links in my iOS app and I can already parse the link, redirect to AppStore etc. Now I want to distinguish the first run of the app, when user installs it from the dynamic link - I want to skip the intro and show him the content that is expected to be shown.

Is there some parameter, that I could catch in application(_:didFinishLaunchingWithOptions:) so I could say that it was launched thru the dynamic link?

The method application(_:continueUserActivity:userActivity:restorationHandler:) is called later, so the intro is already launched.

This case is difficult to test, because you have to have your app published on the AppStore.

jan.zahula
  • 77
  • 4

2 Answers2

4

You actually don't need to have the app published in the App Store for this to work — clicking a link, closing the App Store, and then installing an app build through Xcode (or any other beta distribution platform like TestFlight or Fabric) has exactly the same effect.

According to the Firebase docs, the method that is called for the first install is openURL (no, this makes no sense to me either). The continueUserActivity method is for Universal Links, and is only used if the app is already installed when a link is opened.

I am not aware of any way to detect when the app is opening for the first time after install from a 'deferred' link, but you could simply route directly to the shared content (skipping the intro) whenever a deep link is present. If a deep link is NOT present, show the regular intro.


Alternative Option

You could check out Branch.io (full disclosure: I'm on the Branch team). Amongst other things, Branch is a great, free drop-in replacement for Firebase Dynamic Links with a ton of additional functionality. Here is an example of all the parameters Branch returns immediately in didFinishLaunchingWithOptions:

{  
    "branch_view_enabled"   = 0; 
    "browser_fingerprint_id" = "<null>"; 
    data = "{  
      \"+is_first_session\":false,
      \"+clicked_branch_link\":true,
      \"+match_guaranteed\":true,
      \"$canonical_identifier\":\"room/OrangeOak\",
      \"$exp_date\":0,
      \"$identity_id\":\"308073965526600507\",
      \"$og_title\":\"Orange Oak\",
      \"$one_time_use\":false,
      \"$publicly_indexable\":1,
      \"room_name\":\"Orange Oak\", // this is a custom param, of which you may have an unlimited number
      \"~channel\":\"pasteboard\",
      \"~creation_source\":3,
      \"~feature\":\"sharing\",
      \"~id\":\"319180030632948530\",
      \"+click_timestamp\":1477336707,
      \"~referring_link\":\"https://branchmaps.app.link/qTLPNAJ0Jx\"
    }"; 
    "device_fingerprint_id" = 308073965409112574; 
    "identity_id" = 308073965526600507; 
    link = "https://branchmaps.app.link/?%24identity_id=308073965526600507"; 
    "session_id" = 319180164046538734;
}

You can read more about these parameters on the Branch documentation here.

Community
  • 1
  • 1
Alex Bauer
  • 13,147
  • 1
  • 27
  • 44
  • This is exactly what I was looking for. The firebase docs say that you can test it before it is published, but I didn't know that the process is triggered after I click the AppStore link and then run the app from Xcode. Many thanks! – jan.zahula Oct 26 '16 at 07:28
  • 1
    I ❤️ Branch and think it's a great product, but giving a Firebase + Branch answer for a Firebase question seems a bit wrong. – NSTJ Jun 04 '17 at 17:03
  • 2
    Hey @NSTJ, thanks for the feedback! The OP was asking about something that is not possible to accomplish in Firebase. Hopefully they found it helpful to learn about an alternative solution – Alex Bauer Jun 04 '17 at 17:18
  • problem is that branchio developer experience and the web interface are terrible. – airtonix Apr 26 '22 at 06:30
1

Hmm... as far as I'm aware, there's not really anything you can catch in the application:(_:didFinishLaunchingWithOptions) phase that would let you know the app was being opened by a dynamic link. You're going to have to wait until the continueUserActivity call, as you mentioned.

That said, FIRDynamicLinks.dynamicLinks()?.handleUniversalLink returns a boolean value nearly instantly, so you should be able to take advantage of that to short-circuit your into animation without it being a bad user experience. The callback itself might not happen until several milliseconds later, depending on if it's a shortened dynamic link (which requires a network call) or an expanded one (which doesn't).

Todd Kerpelman
  • 16,875
  • 4
  • 42
  • 40
  • 1
    This should work, though do note that on the initial install, there will still be a network call required even for an expanded link. – Alex Bauer Oct 24 '16 at 18:55
  • I also found out that the method `willContinueUserActivityWithType` is called before the launch screen disappeares. So it is the place to put the "skip intro" logic – jan.zahula Oct 26 '16 at 07:30