问题描述
了解利弊后,我采用了 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 (将#修改为@)