【发布时间】:2017-08-29 09:03:02
【问题描述】:
当我点击推送通知时,我想导航到特定的视图控制器。
我已经在我的 didReceiveRemoteNotification 方法中编写了这段代码。
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "deals") as! FYIDealsVC
let naviVC:UINavigationController? = self.window?.rootViewController?.revealViewController().frontViewController as? UINavigationController
naviVC?.pushViewController(vc, animated: true)
}
但它给了我这个导致应用程序崩溃的错误。
致命错误:在展开可选值时意外发现 nil
有很多关于导航控制器或只是展示视图控制器的帖子。但我想通过显示导航到特定视图。
任何帮助将不胜感激。
【问题讨论】:
-
您确定给定屏幕的情节提要 ID 是“deals”并且它具有
FYIDealsVC类吗? -
是的,仅在这一行中它分解了 let naviVC:UINavigationController? = self.window?.rootViewController?.revealViewController().frontViewController 为? UINavigationController
-
你确定你正在获取导航控制器的对象调试这一行我认为你在这一行 self.window?.rootViewController?.revealViewController().frontViewController 中得到了 nil 吗? UINavigationController
-
嗨,是的,我在那一行得到了零
-
我有另一个解决方案可以尝试使用 window.rootviewcontroller 或者您可以使用通知中心进行导航
标签: ios swift firebase push-notification