6

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.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
m179
  • 89
  • 1
  • 8
  • can you check if you calling this method on link click application:openURL:options: ?? And also what is the link that you click? – m1sh0 Jul 31 '19 at 13:44
  • @m1sh0 , the link I click is myappname.page.link followed by the part of the link which should signal my app to do things, and this opens my app. I don't have that method, however upon implementing it in my app it isn't called either when I click the URL... – m179 Jul 31 '19 at 16:28
  • Did you figure this out? I have the same issue... – user Dec 02 '19 at 08:30

3 Answers3

6

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.

HelloTimo
  • 558
  • 1
  • 5
  • 18
1

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

Sam
  • 161
  • 1
  • 2
  • 10
  • 1
    Hi Sam, thanks for the reply. I have tried this with both [UIUserActivityRestoring] and [Any] in the method declaration, same problem, as mentioned in original post. Have you confirmed it works on latest iOS 13 betas? Cheers. – m179 Aug 19 '19 at 19:15
0

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
    //...
  }
}
DoT
  • 21
  • 3