如何解决如何在应用程序关闭而不是在后台时通过 URL 方案导航到特定的视图控制器
了解利弊后,我采用了 URL 方案。
当应用在后台运行时一切顺利。
但是当应用不在后台运行时,它只能通过 Safari 中的 URL 方案导航到初始视图控制器。
我想知道当应用程序关闭时如何访问特定的视图控制器
以下是我尝试过的代码。
在 SceneDelegate.swift 中
func scene(_ scene: UIScene,openURLContexts URLContexts: Set<UIOpenURLContext>) {
guard let url = URLContexts.first?.url else {
return NSLog("No URL passed to open the app")
}
handleURL(url: url)
print("openURLContexts executed")
}
func handleURL(url: URL) {
let urlComponents = NSURLComponents(url: url,resolvingAgainstBaseURL: true)
let items = urlComponents?.queryItems
guard let _ = items?.first,let propertyName = items?.first?.name,let propertyValue = items?.first?.value else {
print("no URL")
return
}
let destinationVC = UIStoryboard(name: "Main",bundle: nil).instantiateViewController(identifier: "test1") as TagIGottest
if propertyValue == "test1",propertyName == "name" {
print("ready to go to the specific page.")
self.window?.rootViewController?.present(destinationVC,animated: true,completion: nil)
print("handleURL executed")
}
}
谢谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。