2

If you launch your app directly from the dynamic link (and assuming your app is not already running in the background) then application:continueUserActivity is not called.

In the past, we used to rely on the application:didFinishLaunchingWithOptions however as of iOS13 and Xcode 9, that doesn't work anymore. Now when you launch the app from a dynamicLink, the launchOptions is nil and so this doesn't work anymore (An example of this solution that does NOT work anymore is here: https://stackoverflow.com/a/46722785/6553577 )

Does anyone know how to deal with this issue? (Thanks for your response)

MegaMaziar
  • 175
  • 1
  • 9
  • Does this answer your question? [Dynamic Links not working when app is closed, only when in background](https://stackoverflow.com/questions/62683639/dynamic-links-not-working-when-app-is-closed-only-when-in-background) – alegelos Sep 17 '22 at 12:30

2 Answers2

10

Thanks to Matt, and following his suggestion to use scene delegate, I was able to get this to work. For reference, and to help friends from spending hours on this, here is my swift code: (This is tested on iOS v13.3, with Xcode v11.3 and Firebase iOS SDK v6.14.0)

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        guard let _ = (scene as? UIWindowScene) else { return }

        if let userActivity = connectionOptions.userActivities.first {
            if let incomingURL = userActivity.webpageURL {
                _ = DynamicLinks.dynamicLinks().handleUniversalLink(incomingURL) { (dynamicLink, error) in
                    guard error == nil else { return }
                    if let dynamicLink = dynamicLink {
                    //your code for handling the dynamic link goes here
                    }
                }
            }
        }
    }
MegaMaziar
  • 175
  • 1
  • 9
  • 2
    This was exactly my problem. You save me many hours of wasted time. Thank you. Thank you. Thank you @MegaMaziar – MrAliB Jan 20 '20 at 22:58
  • Really appreciated, I was struggling in Firebase deep links and for iOS13 and up there is no documentation available in the Firebase page. – Kampai Mar 17 '21 at 05:24
4

Everything happens in the scene delegate now. Use scene(_:willConnectTo:options:) instead to detect an NSUserActivity or URL context on launch.

matt
  • 515,959
  • 87
  • 875
  • 1,141