Ios swift:在UIAlertView中显示推送通知的内容
如何在swift的UIAlertView中显示FCM推送通知的内容 这是没有帮助的,因为它是用于ObjectiveC 我希望在收到推送通知FCM时,向客户端显示带有特定消息的UIAlertView。例如: 如果从FCM接收到的a在UIAlertView中显示特定消息1,否则如果b 从UIAlertView中的FCM显示特定消息2接收 我刚试过这个,但不适合我:Ios swift:在UIAlertView中显示推送通知的内容,ios,swift,uialertview,firebase-cloud-messaging,Ios,Swift,Uialertview,Firebase Cloud Messaging,如何在swift的UIAlertView中显示FCM推送通知的内容 这是没有帮助的,因为它是用于ObjectiveC 我希望在收到推送通知FCM时,向客户端显示带有特定消息的UIAlertView。例如: 如果从FCM接收到的a在UIAlertView中显示特定消息1,否则如果b 从UIAlertView中的FCM显示特定消息2接收 我刚试过这个,但不适合我: func application(_ application: UIApplication, didReceiveRemoteN
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
// display alert view when notification is received !!!
let alertController = UIAlertController(title: "Alert", message: "you have a new notification", preferredStyle: .alert)
let okAction = UIAlertAction(title: "Yes", style: UIAlertActionStyle.default) {
UIAlertAction in
NSLog("OK Pressed")
}
let cancelAction = UIAlertAction(title: "No", style: UIAlertActionStyle.cancel) {
UIAlertAction in
NSLog("Cancel Pressed")
}
alertController.addAction(okAction)
alertController.addAction(cancelAction)
self.window?.rootViewController?.present(alertController, animated: true, completion: nil)
}
当您尝试显示警报时,控制台中是否出现任何错误?有时,当从AppDelegate演示内容时,我会看到如下情况:
2017-01-01 16:04:14.806 wylt[46457:5781064] Warning: Attempt to present <UIAlertController: 0x7faf13f0a910> on <wylt.WYLTNavigationViewController: 0x7faf1402e200> whose view is not in the window hierarchy!
…没什么很难为你调试。你有没有在iOS上收到通知?如果手机被锁定,你会在锁屏上收到警报吗?是的…iphone收到了通知…注意UIAlertView已被弃用,你应该改用UIAlertController。我知道…但我的问题是其他的
DispatchQueue.main.async {
self.window?.rootViewController?.present(alertController, animated: true, completion: nil)
}