I have a question. in "class SceneDelegate"
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
let url = userActivity.webpageURL
print(url) //result is www.mywebsite.com
}
how can I pass this url to my ViewController???
I have a question. in "class SceneDelegate"
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
let url = userActivity.webpageURL
print(url) //result is www.mywebsite.com
}
how can I pass this url to my ViewController???
It'll depend on the view controller hierarchy you have, but let's say you have a UITapBarController
as your root view controller and you want to eventually get to a view controller that's within a navigation controller:
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
let url = userActivity.webpageURL
if let windowScene = scene as? UIWindowScene {
for window in windowScene.windows {
if let rootViewController = window.rootViewController {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
if let yourVC = storyboard.instantiateViewController(withIdentifier: "YourVC") as? YourViewController,
let tabBarController = rootViewController as? UITabBarController,
let navController = tabBarController.selectedViewController as? UINavigationController {
yourVC.data = url
navController.pushViewController(yourVC, animated: true)
}
}
}
}
}
Update
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
let url = userActivity.webpageURL
if let windowScene = scene as? UIWindowScene {
for window in windowScene.windows {
if let rootViewController = window.rootViewController {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
if let yourVC = storyboard.instantiateViewController(withIdentifier: "EventViewController") as? EventViewController,
let navController = rootViewController as? UINavigationController {
yourVC.data = url
navController.pushViewController(yourVC, animated: true)
}
}
}
}
}