當我單擊推送通知時,我想導航到特定的視圖控制器。導航到單擊具有Reveal的推送通知時的特定視圖
我在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)
}
但它給我這個崩潰的應用程序的錯誤。
fatal error: unexpectedly found nil while unwrapping an Optional value
有很多帶有導航控制器的帖子或只是提供了viewcontroller。但我想用揭示導航到具體的視圖。
任何幫助將不勝感激。
你確定給定屏幕的故事板ID是 「交易」,它具有類'FYIDealsVC'? – the4kman
是的,在這一行中只有它分解了 讓naviVC:UINavigationController? = self.window?.rootViewController?.revealViewController()。frontViewController as? UINavigationController – NavodaP
你確定你正在獲取導航控制器的對象調試這一行我認爲你在這一行self.window?.rootViewController?.revealViewController()。 UINavigationController – Pushpendra