I have faced the problem that I can't solve with Notifications and Deeplinks.
When opening a deeplink UIApplication used to send a UIApplication.didFinishLaunchingNotification with userInfo that contained UIApplicationLaunchOptionsURLKey with the URL that was opened.
So we could subscribe to it like this:
NotificationCenter.default.addObserver(forName: UIApplication.didFinishLaunchingNotification, object: nil, queue: nil) { (notification) in
print(notification.userInfo) // prints UIApplicationLaunchOptionsURLKey: url_that_opened_the_app
}
Now, after iOS 13 it does not happen: userInfo is nil.
So the question is: is there a way to receive a notification from Notification Center when app opens a deeplink?
*Thoughts: *
I think that it is caused by the fact that UISceneDelegate is in charge of opening deeplinks now, which is confirmed by the fact that if we remove the SceneDelegate, we can get our userInfo back.
I tried to find if any of SceneDelegate notifications provide us with such information, but they don't: both didActivateNotification and willConnectNotification give nothing.
Yes, you can find the same with
SceneDelegateas well.Here is a Sample I made.
Once you launch your app from deep links, you will receive
connectionOptionsinYou can get your URL as follows:
So your function will look like:
DeepLink I tested was:
deeplinks://mycustomDeepLink
Also I changed the scheme to
Wait for the Executable to Launchto check the initial launch thing from deep links.Note: Sometimes debugger doesn't work for whatsoever reason. So, in my sample, I added an alert view in the
ViewController.