2017-01-01 5 views
-2

UIAlertViewでプッシュ通知(FCM)の内容を迅速に表示するにはどうすればよいですか?それがObjectiveCのためであるのでswift:UIAlertViewでプッシュ通知の内容を表示

このlinkは、プッシュ通知(FCM)は、特定のメッセージをクライアントにUIAlertViewを表示するために受信したときに、私が欲しい...

有用ではなかったです。例えば:

場合( "" FCMから受信した)他の表示 "UIAlertViewに特定のメッセージ1"、IF(FCMから受信した "B" )表示 "UIAlertViewに特定のメッセージ2"。

私はこれを試してみましたが、それは私のために働いていない:あなたは、アラートを提示しようとすると、

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) 

} 
+0

... nothing ... –

+0

これをデバッグするのは難しいです。あなたはiOSで通知を受け取りますか?電話がロックされている場合は、ロック画面にアラートが表示されますか? – Alistra

+0

はい... iphoneが通知を受け取りました... –

答えて

0

あなたのコンソールにエラーを取得していますか?私はトップビューコントローラを見つけて、代わりにそこからの警告を提示することを好む...だけでなく、働いていた非同期ブロックの内部に存在するコールを入れ

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! 

AppDelegateから物事を提示するときとき時々私はこのような何かを参照してください私のために。

DispatchQueue.main.async { 
    self.window?.rootViewController?.present(alertController, animated: true, completion: nil) 
} 
関連する問題