我在其中实现了UserNotifications的LocalNotification类。我在我需要提供的初始ViewController和CheckViewController之间创建了segue。那是我的didReceive responce
功能
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let nav = storyboard.instantiateInitialViewController() as! UINavigationController
let mainViewController = nav.topViewController as! ViewController
mainViewController.performSegue(withIdentifier: "CheckSegue", sender: nil)
}
但我仍然得到 - 是最初的ViewController。我哪里错了?
答案 0 :(得分:1)
MainViewController
是初始视图控制器吗?如果是这样,您看到的实例是应用程序的根。您正在创建一个不可见的全新实例。
尝试
let nav = UIApplication.shared.keyWindow?.rootViewController as? UINavigationController
而不是
let nav = storyboard.instantiateInitialViewController() as! UINavigationController