我正在尝试快速实现通用链接,但是当应用程序尚未打开时出现问题。当应用程序之前打开时它工作得很好,它将导航到正确的视图控制器。当应用程序尚未打开时,它不会导航到所需的视图控制器,我认为它与根视图控制器有关,但并不积极。有没有人处理过同样的问题?
在AppDelegate
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
let navigator = Navigator()
if let url = userActivity.webpageURL {
navigator.getDesination(for: url)
}
}
该getDestination
函数最终将最终触发以下代码:
func openPostVC(id: Int, showComment: Bool, commentID: Int?) {
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
return }
if let _ = appDelegate.window?.rootViewController as? BannedViewController { return }
let postStoryboard = UIStoryboard.singlePost
let singlePostVC = postStoryboard.instantiateInitialViewController() as! SinglePostViewController
singlePostVC.shouldNavigateToHomeAction = {
self.loadMainStoryboard()
}
let navigationVC = UINavigationController(rootViewController: singlePostVC)
navigationVC.view.backgroundColor = .white
appDelegate.window?.rootViewController = navigationVC
appDelegate.window?.makeKeyAndVisible()
}