I'm trying to run app by using universal links. I want to make sure that when I open the app through universal links, the app runs and go to the viewcontroller I want. it works when app is still alive or already in background. But if the app is killed, the universal links just run the app but not go to the viewcontroller I want.
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
if userActivity.activityType == NSUserActivityTypeBrowsingWeb{
guard let url = userActivity.webpageURL else { return }
print(url)
let nextVc = nextVC()
nextVc.modalPresentationStyle = .fullScreen
self.window?.rootViewController?.present(nextVc, animated: true, completion: nil)
}
this is what I have done in func scene(_ scene: UIScene, continue userActivity: NSUserActivity).it works when app is alive.
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
...
let userActivity = connectionOptions.userActivities.first
if userActivity!.activityType == NSUserActivityTypeBrowsingWeb {
let incomingURL = userActivity!.webpageURL
let components = NSURLComponents(url: incomingURL!, resolvingAgainstBaseURL: true)
print (incomingURL)
} else {print("nothing") }
..
}
And this is what I have tried at func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) . To see if I can get the url but I found the userActivity is nil. what should I do?