I am looking for a way to retrieve the universal link full URL inside my swift app.
- My universal link setup is (I think) complete in that clicking a link in Safari opens my app in the emulator.
- My app is handling 100% of the functionality of the associated domain (app.mycompany.io)
Here is my apple-app-site-association
:
$ curl https://app.mycompany.io/.well-known/apple-app-site-association
{
"applinks": {
"details": [
{
"appIDs": [ "ABCD1234.io.mybundle" ],
"paths": [
"*"
],
"components": [
{"/": "/*"}
]
}
]
}
}
Here is the main classes for my app:
struct MyApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
@ObservedObject var model = MyAppModel()
var body: some Scene {
return WindowGroup() {
...
}
}
}
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
// Here I initialize my app
return true
}
func application(_ application: UIApplication, continue userActivity: NSUserActicity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
// Here I thought I could grab the universal link clicked to act accordingly
return true
}
}
My problem is that the second function in my AppDelegate
class never gets called. Not when I launch the app from the home screen, not when I launch the app when clicking in a link (mail or Safari) nor when I put the app back in the focus after it being in the background when clicking a link.
I need a way to extract the link that was clicked to know what my app is supposed to do:
- At startup upon a click on a universal link
- Also when a link is clicked and brings the app in the foreground