Michael
Michael

Reputation: 89

"continue userActivity" method not called, despite Firebase deep link successfully opening app

I'm using Firebase's deep linking to try and provide a certain function in my app when a user clicks a link that was sent to them. The deep link is setup properly on the Firebase web portal.

Clicking the link sent to the user DOES open my app, but does not trigger the continue userActivity method in my App Delegate, as none of the code contained in there is every executed.

I've tried the solution suggested in this StackOverflow post but no success, that's switching [UIUserActivityRestoring] to [Any] in the method declaration.

In Xcode, I have setup the associated domain to match what I set on Firebase: applinks:myappname.page.link; and I have added a "URL type" with identifier "Bundle ID", and URL scheme of ca.mycompany.myappname, with role editor.

All this is running on-device, of course, as I don't expect this to work in the simulator.

This is the method in my app delegate which should be called, however is not.

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
print ("The link worked")

}

I made sure didFinishLaunchingWithOptions returns true always as well.

I expect the "The link worked" to actually print in debugging console, but it does not. Breakpoints indicate the method isn't being called at all, as the breakpoints are never reached.

Upvotes: 6

Views: 2184

Answers (3)

DoT
DoT

Reputation: 31

For scene application try to add your logic as part of

func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
  let handled = DynamicLinks.dynamicLinks().handleUniversalLink(userActivity.webpageURL!) { (dynamiclink, error) in
    //...
  }
}

Upvotes: 1

HelloTimo
HelloTimo

Reputation: 578

There is a good change that somebody facing this problem deals with iOS13 / SwiftUI, too. Just like me.

I have found this article which solved all my problems.

Basically you have to be aware that some methods from the new SceneDelegate replace what was called in AppDelegate before iOS 13. Additionally there seem to be edge cases where methods from the AppDelegate still might be needed to handle deeplinks processing.

Upvotes: 6

Sam
Sam

Reputation: 161

For anyone who needs it:

you need to use the below code to handle deep links from the link to the app that is already installed(other func application are for different things)

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool { let handled = DynamicLinks.dynamicLinks().handleUniversalLink(userActivity.webpageURL!) { (dynamiclink, error) in // ... } return handled }

https://firebase.google.com/docs/dynamic-links/ios/receive #6

Upvotes: 1

Related Questions