Reputation: 1
I implemented Universal Links successfully in my app (as in, it opens to app with the URL link instead of Safari). However, I am trying to extend this to Deeplink. Afaik, I should be able to do this within this function:
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool
However, this function doesn't even get called for me. I verified this with a bunch of print and log statements that never get called. I have tried revising my implementation of Universal Links many times, but can't seem to find the issue. Would appreciate any insight.
I tried implementing
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool
but that function doesn't even get called when opening the URL
Upvotes: 0
Views: 88
Reputation: 715
Scene based iOS apps don't call the mentioned methods of your application delegate.
If your app has opted into Scenes, and your app is not running, the system delivers the universal link to the scene(_:willConnectTo:options:) delegate method after launch, and to scene(_:continue:) when the universal link is tapped while your app is running or suspended in memory.
See Apple's article Supporting universal links in your app
If your app doesn't have a UISceneDelegate yet, there are multiple ways to add one. Apple describes them in the linked UISceneDelegate
documentation.
For simple cases, you can also use the onOpenURL method in SwiftUI:
@main
struct DemoApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.onOpenURL { url in
// deep link handling
}
}
}
}
Upvotes: 0