-2
如何在swift中显示UIAlertView中推送通知(FCM)的内容?swift:在UIAlertView中显示推送通知的内容
这link是没有帮助的,因为它是对的ObjectiveC ...
我要当接收到显示UIAlertView中具有特定消息的客户端推送通知(FCM)。例如:
如果( “A” 从FCM接收的)显示 “特定的消息1 UIAlertView中”,否则,如果( “B” 从 FCM接收的)显示 “特定的消息2中UIAlertView中”。
我只是尝试这样做,但它不工作对我来说:
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)
}
...什么都没有... –
这很难为您调试。你甚至在iOS上收到通知吗?如果手机被锁定,您是否会在锁屏上看到警报? – Alistra
是的... iphone收到通知... –