【发布时间】:2018-02-16 00:22:54
【问题描述】:
我的推送通知点击有问题。每次用户点击通知时,应用程序都会崩溃,而不是将用户重定向到指定页面。
这部分代码导致错误“无法将'appname.LaunchScreenController'类型的值转换为'UINavigationController'” :
let rootViewController = self.window!.rootViewController as! UINavigationController
这段代码会导致fatal error: unexpectedly found nil while unwrapping an Optional value:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
//receive the notifications
NotificationCenter.default.post(name: Notification.Name(rawValue: "MyNotificationType"), object: nil, userInfo: userInfo)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "NewsController") as! NewsViewController
let rootViewController = self.window!.rootViewController as! UINavigationController
rootViewController.pushViewController(vc, animated:true)
}
提前致谢
【问题讨论】:
标签: ios xcode swift3 onesignal