當應用程序關閉時,我有FCM通知工作,但當應用程序打開並在前臺運行時,我無法讓它們正常工作。 「Swift和Firebase雲消息傳遞通知僅在應用程序泄露時起作用
我收到以下錯誤」警告:應用程序委託收到對應用程序的調用:didReceiveRemoteNotification:fetchCompletionHandler:但完成處理程序從未調用。我一直在谷歌搜索幾個小時,閱讀firebase文檔,但我不確定如何克服這個錯誤。
// [START receive_message]
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
// If you are receiving a notification message while your app is in the background,
// this callback will not be fired till the user taps on the notification launching the application.
// TODO: Handle data of notification
// Print message ID.
print("Message ID: \(userInfo["gcm.message_id"]!)")
// Print full message.
print("%@", userInfo)
////new code to help with error but no luck
if application.applicationState == UIApplicationState.Active {
print("%@", userInfo)
print("message recieved")
}
}
加入以下代碼沒有工作
if application.applicationState == UIApplicationState.Active {
print("%@", userInfo)
print("message recieved") }
任何幫助或建議,將不勝感激
我沒有做任何更改,但現在我可以在應用程序關閉時收到通知,但是當它打開時它不會崩潰但不顯示通知。我可以在控制檯中打印通知。我想我需要創建一個本地通知或東西 –