La FCM les notifications Push ne fonctionne pas sur iOS 11
- Je utiliser Firebase comme un backend. J'utilise aussi de la FCM comme l'une des caractéristiques de Firebase. La FCM a bien fonctionné dans iOS 10, mais après le passage à iOS 11, les notifications push cessé de venir les appareils d'un utilisateur, et j'ai moi-même ne recevez pas les notifications push envoyées à partir du nuage de fonctions ou de la Notification dans la section de Firebase de la Console. Comment résoudre ce problème?
Mise à jour: j'ai envoyé plusieurs notifications push Firebase Notifcations, mais ils ne viennent pas.
//MARK: - Push notification
extension AppDelegate: UNUserNotificationCenterDelegate {
func registerPushNotification(_ application: UIApplication) {
//For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
//For iOS 10 data message (sent via FCM)
Messaging.messaging().delegate = self
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
//When the notifications of this code worked well, there was not yet.
Messaging.messaging().apnsToken = deviceToken
}
//[START receive_message]
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
//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.
if let messageID = userInfo[gcmMessageIDKey] {
debugPrint("Message ID: \(messageID)")
}
//Print full message.
debugPrint(userInfo)
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (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.
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
//Print full message.
debugPrint(userInfo)
completionHandler(.newData)
}
//showing push notification
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
if let userInfo = response.notification.request.content.userInfo as? [String : Any] {
let routerManager = RouterManager()
routerManager.launchRouting(userInfo)
}
completionHandler()
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
if let userInfo = notification.request.content.userInfo as? [String : Any] {
if let categoryID = userInfo["categoryID"] as? String {
if categoryID == RouterManager.Categories.newMessage.id {
if let currentConversation = ChatGeneralManager.shared.currentChatPersonalConversation, let dataID = userInfo["dataID"] as? String {
//dataID is conversationd id for newMessage
if currentConversation.id == dataID {
completionHandler([])
return
}
}
}
}
if let badge = notification.request.content.badge {
AppBadgesManager.shared.pushNotificationHandler(userInfo, pushNotificationBadgeNumber: badge.intValue)
}
}
completionHandler([.alert,.sound, .badge])
}
}
//[START ios_10_data_message_handling]
extension AppDelegate : MessagingDelegate {
func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
let pushNotificationManager = PushNotificationManager()
pushNotificationManager.saveNotificationTokenInDatabase(token: fcmToken, success: nil, fail: nil)
}
//Receive data message on iOS 10 devices while app is in the foreground.
func application(received remoteMessage: MessagingRemoteMessage) {
debugPrint(remoteMessage.appData)
}
}
OriginalL'auteur Alexander | 2017-09-24
Vous devez vous connecter pour publier un commentaire.
Il apparaît que FirebaseInstanceID 2.0.3 les notifications push ne fonctionne pas. Il m'a aidé à définir: pod "FirebaseInstanceID', "2.0.0".
Peut-être dans la prochaine version cela sera corrigé.
Oui, il y a un bug dans FirebaseInstanceID 2.0.1–2.0.3 qui est résolu dans la prochaine version de Firebase. Les deux solutions (a) Toujours faire appel à
application.registerForRemoteNotifications()
sur l'app démarrer, ou (b) de verrouiller temporairement à FirebaseInstanceID 2.0.0.Pour info, nous avons publié
FirebaseInstanceID 2.0.4
aujourd'hui, ce qui devrait résoudre les problèmes que vous avez vu. Veuillez mettre à jour que si vous deviez avoir des problèmes avec la 2.0.1–2.0.3. Merci!mis à jour 2.0.5 - fonctionne très bien maintenant
Using FirebaseInstanceID (2.0.6)
et la réception de la notification de la réponse comme un succès, mais toujours pas de notification indiqué sur ios11.1.1
...application.registerForRemoteNotifications()
est également présent. Est-il une vraie solution pour cela?OriginalL'auteur
Veuillez mettre à jour votre FCM pod
à la dernière version, qui est 2.0.6
Il devrait fonctionner avec iOS 11+ périphériques.
OriginalL'auteur
J'ai lu ce sujet et a ajouté ce code
application.registerForRemoteNotifications()
à l'AppDelegate méthodedidFinishLaunchingWithOptions
et cela a fonctionné, mais, malheureusement, les utilisateurs actuels ne recevrez pas de notification jusqu'à ce qu'ils soient mis à jour pour la nouvelle version. Veuillez voir https://github.com/firebase/quickstart-ios/issues/327#issuecomment-331782299il fonctionne pour moi
OriginalL'auteur