-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收到通知... –