【发布时间】:2019-02-15 04:30:35
【问题描述】:
我使用firebase向ios设备发送消息,我调试,我在func的Appdelegate中收到了数据有效负载
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
我想做如何根据那个数据打开不同的视图控制器,也就是说当我点击消息时,我会去对应的视图控制器。 我在 Appdelegate 中使用了下面的代码但失败了
let sb = UIStoryboard(name: "Main", bundle: nil)
let otherVC = sb.instantiateViewController(withIdentifier: "UserNotLoginViewController") as! UserNotLoginViewController
self.window?.rootViewController = otherVC;
【问题讨论】:
-
检查您的 otherVC 对象以及它不应该为 nil 的窗口对象!哇,你是在调用 show VC code 吗?
-
如果 nil 则应用程序将崩溃,但我的应用程序只是没有打开不同的 Viewcontrollers
-
nil 并不意味着应用程序总是会崩溃!
标签: ios swift firebase push-notification firebase-cloud-messaging