11

La nuit dernière, j'ai testé la notification push en utilisant FCM dans mes applications et il est tombé en panne (il fonctionnait il y a quelques jours). Je l'ai testé en utilisant le menu de notification dans la console Firebase. J'étudie en outre le format de la charge utile de notification a été modifié et n'inclut pas le format iOS comme le Apple Documentation.Firebase Cloud Messaging Notification n'envoie pas de format de charge utile iOS

Je re-vérifier mon certificat APNs et le développement était parti, j'essaye de re-télécharger le certificat et il a obtenu l'erreur semblable like this one.

J'ai soumis un commentaire à l'équipe Firebase et j'ai dit que c'était un problème à leur fin. (Note: je poste également la réponse de l'équipe Firebase dans le lien ci-dessus). Mon certificat Dev APNs est de retour, mais le format reste le même.

est ici la charge utile je suis arrivé (de la fonction Swift Imprimer)

{ 
    "collapse_key" = "com.xxx.xxx"; 
    from = xxx; 
    notification =  { 
     badge = 3; 
     body = "Firebase console"; 
     e = 1; 
     title = Test; 
    }; 
} 

Et cette charge font iOS ne sera pas afficher la notification push.

Et sur la base this FCM documentation for iOS

le code suivant fera l'application plantait lors de la notification venir

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) 
} 
  • J'essaie déjà de re-télécharger mon certificat Dev APNs mais l'erreur
  • J'ai aussi envoyer un autre commentaire mais l'équipe Firebase ne répond pas encore

Ai-je raté quelque chose?

Edit:

Comme je l'ai dit ci-dessus, il a été travaux il y a quelques jours, et il devient plantage lors this issue apparaît. En particulier, cette ligne va faire planter l'application, et je suppose que c'est parce que le format de la charge utile a changé (la charge utile aps est manquante).

print("Message ID: \(userInfo["gcm.message_id"]!)") 

Le code fonctionne bien lorsque l'enlever (et produire ci-dessus), mais je ne suis pas le format de la charge utile aps si la notification ne sera jamais pop lorsque les applications en arrière-plan. Aussi mon gestionnaire de notification ne fonctionnera pas lorsque les applications en premier plan.

Edit 2:

J'enregistre déjà une notification dans mon AppDelegate

let setting = UIUserNotificationSettings(forTypes: [.Sound, .Alert, .Badge] , categories: nil) 
    application.registerUserNotificationSettings(setting) 
    application.registerForRemoteNotifications() 

Je suis conscient de cela et déjà permis notification Push et en arrière-plan de la notification à distance.

Capabilities

Modifier 28 Juin 2016:

J'ai essayé de pousser à nouveau la notification de la console firebase, et encore je le même format de charge utile comme celui-ci

%@ [notification: { 
    badge = 2; 
    body = "Test Message"; 
    e = 1; 
    sound = default; 
    sound2 = default; 
    title = Test; 
}, collapse_key: com.xxx, from: 717xxxxxx] 

Ma FCM Firebase Console Le réglage ressemble à ceci:

Firebase Console Setting

Modifier 8 Juillet 2016:

Ceci est mon code AppDelegate

@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate { 

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 

     // Firebase 
     let setting = UIUserNotificationSettings(forTypes: [.Sound, .Alert, .Badge] , categories: nil) 
     application.registerUserNotificationSettings(setting) 
     application.registerForRemoteNotifications() 

     FIRApp.configure() 

     print(FIRInstanceID.instanceID().token()) 

     FIRAnalytics.logEventWithName(kFIREventAppOpen, parameters: nil) 

     NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(tokenRefreshNotificaiton), name: kFIRInstanceIDTokenRefreshNotification, object: nil) 

     return true 
    } 

    // MARK - Firebase 
    func connectToFcm() { 
     FIRMessaging.messaging().connectWithCompletion { (error) in 
      if (error != nil) { 
       print("Unable to connect with FCM. \(error)") 
      } else { 
       print("Connected to FCM.") 
      } 
     } 
    } 

    func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) { 
     // 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) 

     var body = "" 
     var title = "20Fit" 

     guard let aps = userInfo["aps"] as? [String : AnyObject] else { 
      print("Error parsing aps") 
      return 
     } 

     if let alert = aps["alert"] as? String { 
      body = alert 
     } else if let alert = aps["alert"] as? [String : String] { 
      body = alert["body"]! 
      title = alert["title"]! 
     } 

     let banner = Banner(title: title, subtitle: body, image: nil, backgroundColor: UIColor.blackColor(), didTapBlock: nil) 
     banner.show(duration: 5.0) 
    } 

    func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { 
      FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: .Sandbox) 
    } 

    func tokenRefreshNotificaiton(notification: NSNotification) { 
     let refreshedToken = FIRInstanceID.instanceID().token()! 
     print("InstanceID token: \(refreshedToken)") 

     sendTokenToServer() 

     // Connect to FCM since connection may have failed when attempted before having a token. 
     connectToFcm() 
    } 

    func applicationWillResignActive(application: UIApplication) { 
     // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 
     // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 
    } 

    func applicationDidEnterBackground(application: UIApplication) { 
     // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 
     FIRMessaging.messaging().disconnect() 
     print("Disconnected from FCM") 
    } 

    func applicationWillEnterForeground(application: UIApplication) { 
     // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 
    } 

    func applicationDidBecomeActive(application: UIApplication) { 
     connectToFcm() 
     // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 
    } 

    func applicationWillTerminate(application: UIApplication) { 
     // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 
     FIRAnalytics.logEventWithName("app_terminated", parameters: nil) 
    } 


} 

Voici le journal complet de mes applications

2016-07-08 19:26:48.022 20FIT Member[2525:1122556] WARNING: Firebase Analytics App Delegate Proxy is disabled. To log deep link campaigns manually, call the methods in FIRAnalytics+AppDelegate.h. 
2016-07-08 19:26:48.273 20FIT Member[2525:1122556] Configuring the default app. 
2016-07-08 19:26:48.318 20FIT Member[2525:] <FIRAnalytics/DEBUG> Debug mode is on 
2016-07-08 19:26:48.338 20FIT Member[2525:] <FIRAnalytics/INFO> Firebase Analytics v.3200000 started 
2016-07-08 19:26:48.338 20FIT Member[2525:] <FIRAnalytics/INFO> To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see google link) 
2016-07-08 19:26:48.343: <FIRInstanceID/WARNING> Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)" 
2016-07-08 19:26:48.350: <FIRMessaging/INFO> FIRMessaging library version 1.1.0 
2016-07-08 19:26:48.339 20FIT Member[2525:] <FIRAnalytics/DEBUG> Debug logging enabled 
2016-07-08 19:26:48.365 20FIT Member[2525:] <FIRAnalytics/DEBUG> Uploading data. Host: https://play.googleapis.com/log 
2016-07-08 19:26:48.366 20FIT Member[2525:] <FIRAnalytics/DEBUG> Firebase Analytics is monitoring the network status 
Optional("cXwsIWfiJas:APA91bGjUnL-oztH9LntO4EaKdJxPQN_-Za5ydC-hPR-_HPZXNm4m_mzqSztvbBG7HczNN5Jr7Btr8h4ETF5FyOOUn8Ombk4c3RoTL6GDFrh6BnG0ECs_r_Hqx1dnVHeJVwLQo4JInn2") 
2016-07-08 19:26:48.406 20FIT Member[2525:] <FIRAnalytics/DEBUG> Successfully parsed a configuration. Version: 1464617411301000 
2016-07-08 19:26:48.429 20FIT Member[2525:] <FIRAnalytics/DEBUG> Firebase Analytics is ready to receive events 
2016-07-08 19:26:48.432 20FIT Member[2525:] <FIRAnalytics/DEBUG> No network. Upload task will not be scheduled 
2016-07-08 19:26:48.434 20FIT Member[2525:] <FIRAnalytics/DEBUG> Cancelling background upload task. 
2016-07-08 19:26:48.437 20FIT Member[2525:] <FIRAnalytics/DEBUG> Scheduling user engagement timer 
2016-07-08 19:26:48.438 20FIT Member[2525:] <FIRAnalytics/DEBUG> Timer scheduled to fire in approx. (s): 3600 
2016-07-08 19:26:48.441 20FIT Member[2525:] <FIRAnalytics/INFO> Firebase Analytics enabled 
2016-07-08 19:26:48.445 20FIT Member[2525:] <FIRAnalytics/DEBUG> Logging event: origin, name, params: app, app_open, { 
     "_o" = app; 
    } 
2016-07-08 19:26:48.477 20FIT Member[2525:] <FIRAnalytics/DEBUG> Scheduling user engagement timer 
2016-07-08 19:26:48.478 20FIT Member[2525:] <FIRAnalytics/DEBUG> Canceling active timer 
2016-07-08 19:26:48.479 20FIT Member[2525:] <FIRAnalytics/DEBUG> Timer scheduled to fire in approx. (s): 3600 
2016-07-08 19:26:48.562 20FIT Member[2525:] <FIRAnalytics/DEBUG> Network status has changed. code, status: 2, Connected 
2016-07-08 19:26:48.566 20FIT Member[2525:] <FIRAnalytics/DEBUG> Network status has changed. code, status: 2, Connected 
2016-07-08 19:26:48.618 20FIT Member[2525:] <FIRAnalytics/DEBUG> Event logged. Event name, event params: app_open, { 
     "_o" = app; 
    } 
2016-07-08 19:26:48.635 20FIT Member[2525:] <FIRAnalytics/DEBUG> Timer scheduled to fire in approx. (s): 3143.319384038448 
2016-07-08 19:26:48.636 20FIT Member[2525:] <FIRAnalytics/DEBUG> Upload task scheduled to be executed in approx. (s): 3143.319384038448 
2016-07-08 19:26:48.637 20FIT Member[2525:] <FIRAnalytics/DEBUG> Do not schedule an upload task. Task already exists 
2016-07-08 19:26:48.710 20FIT Member[2525:] <FIRAnalytics/DEBUG> Received SSL challenge for host. Host: https://play.googleapis.com/log 
2016-07-08 19:26:49.408 20FIT Member[2525:] <FIRAnalytics/DEBUG> Uploading data. Host: https://play.googleapis.com/log 
Connected to FCM. 
2016-07-08 19:26:49.869 20FIT Member[2525:] <FIRAnalytics/DEBUG> Received SSL challenge for host. Host: https://play.googleapis.com/log 
2016-07-08 19:26:50.206 20FIT Member[2525:] <FIRAnalytics/DEBUG> Uploading data. Host: https://play.googleapis.com/log 
2016-07-08 19:26:50.723 20FIT Member[2525:] <FIRAnalytics/DEBUG> Received SSL challenge for host. Host: https://play.googleapis.com/log 
%@ [notification: { 
    badge = 2; 
    body = "Test Message"; 
    e = 1; 
    sound = default; 
    sound2 = default; 
    title = Yoiii; 
}, collapse_key: com.xxx.xxx, from: 717xxxx] 
Error parsing aps 
+0

Hey j'ai le même problème. Ma clé aps est également manquante. Avez-vous trouvé une solution? – MrDank

+0

malheureusement pas encore, je contacte déjà le support Firebase mais malheureusement, ils sont lents à répondre (le statut est que nous étudions). –

+0

Vérifie ma réponse. – MrDank

Répondre

0

La 'charge utile' que vous avez fourni a été (vraisemblablement) produite par la dernière ligne de la méthode didReceiveRemoteNotification, soit print("%@", userInfo).

Vous affirmez que le code ci-dessus fait planter l'application, ce qui est en contradiction avec l'impression réussie de ce code dans le journal.

Je pense que quelque chose d'autre plante votre application. Avez-vous regardé dans le journal du système? (Si vous utilisez le simulateur, allez à Déboguer> Ouvrir le journal du système).

Je suggère d'exécuter l'application de démonstration Firebase (pod try Firebase), pour vous convaincre que cela fonctionne comme vous l'attendez.

+0

Salut merci pour votre réponse, j'essaie de l'expliquer clairement, vérifiez la section EDIT :) –

+0

Oui, il n'y a aucun champ par ce nom dans le userInfo (comme vous pouvez le voir du résultat de l'impression ("% @", userInfo)). Je soupçonne que c'est une relique de quand Firebase était GCM, et est une erreur dans le code d'exemple fourni par Firebase. Il suffit de le supprimer, ce n'est pas nécessaire! – IanS

+0

Lorsque vous dites "je ne reçois pas le format de charge utile", souvenez-vous que vous imprimez simplement l'objet "userInfo", et non la charge utile réelle. Courez-vous dans le simulateur ou sur un vrai appareil? – IanS

1

La «charge utile» que vous imprimez me semble juste. Cependant, notez que c'est pas la charge utile APN. C'est en fait un dictionnaire d'info-utilisateur. Si je comprends votre question, vous semblez s'inquiéter du champ "aps" manquant. Vous ne verrez pas ce champ dans le dictionnaire d'informations utilisateur.

Courez-vous ceci sur un vrai appareil ou dans le simulateur? N'oubliez pas que le simulateur ne peut pas afficher les notifications à distance, et sur un périphérique réel, l'application doit être en arrière-plan pour afficher les notifications.

Essayez d'envoyer une notification locale (le programmer pendant 30 secondes temps):

localNotif.fireDate = [[NSDate date] dateByAddingTimeInterval:30]; 

et appuyez sur la touche d'accueil et d'attendre.

+0

oui, je suis au courant des capacités de notification push, je cours dans le vrai appareil, mes applications fonctionnent en arrière-plan, mais rien. comme je l'ai déjà dit, mes applications fonctionnent bien il y a quelques jours, je reçois le format de charge utile aps, mais maintenant ne fonctionne pas :(Merci pour votre réponse –

0

Je cherche à savoir pourquoi votre gcm.message_id est nul, donnez-moi quelques jours.

Pour ne pas obtenir la notification lorsque l'application est en arrière-plan, assurez-vous que vous vous inscrivez pour les notifications à distance comme indiqué dans l'échantillon de QuickStart (voir didFinishLaunchingWithOptions) ici: https://github.com/firebase/quickstart-ios/blob/master/messaging/FCMSwift/AppDelegate.swift

Aussi, assurez-vous dans Xcode » Définissez vos capacités pour permettre le traitement des notifications en arrière-plan.

+1

Salut merci, abput registre pour notification à distance activer push et notification à distance dans xcode capacités que j'ai déjà fait cela, vérifiez mon Edit 2 –

+0

Je voyage donc ne sera pas en mesure de se pencher sur cela profondément jusqu'à mardi Le code que j'ai lié a une clause de secours pour non iOS 8 - avez-vous implémenté cela? En outre, avez-vous fait le Firapp.Configure() Enfin, si * a * fonctionnait, et s'est arrêté au moment où il y avait des problèmes en téléchargeant le .p12, avez-vous essayé d'en générer un nouveau et de le télécharger? –

+0

mes applications ne supportent que iOS 8 ci-dessus aussi j'utilise le périphérique iOS 9.3, j'ai fait FIRApp.configure(), je télécharge aussi mon .p12. Je vais essayer de générer à nouveau le .p12 –

0

Même problème ici.De plus, le message Firebase avec la clé 'aps' ne semble pas être livré lors de l'envoi avec la console. Doit être des bogues avec Firebase pour changer le format de charge utile. A propos de la notification de Firebase en arrière-plan, dans ce cas, iOS ne reconnaîtra pas le format de la charge utile -> pas d'avis du tout. Pour lire le message de Firebase en arrière-plan, n'appelez pas FIRMessaging.messaging(). Disconnect() lorsque vous passez en mode arrière-plan. Ensuite, vous devriez recevoir votre message et le gérer de votre propre main (toujours pas de notification système).

4

J'ai eu le même problème

En ce qui concerne cette partie des guides fcm: https://firebase.google.com/docs/cloud-messaging/ios/client#swizzling_disabled_receive_messages_through_the_messaging_apns_interface

Je résolus problème avec l'ajout setAPNSToken:type:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken 
{ 
    [[FIRInstanceID instanceID] setAPNSToken:deviceToken type:FIRInstanceIDAPNSTokenTypeSandbox]; 
} 

Après que fcm a commencé à envoyer des poussées avec la charge utile formaté correctement pour iOS .

pour Ofcourse enviromnent de production utiliser FIRInstanceIDAPNSTokenTypeProd

+0

Salut, j'ai essayé votre suggestion, mais cela ne fonctionne pas pour moi :( –

0

Je suis passé par le forum des développeurs d'Apple et il semble que didRegisterForRemoteNotificationsWithDeviceToken ne fonctionnait pas en mode sandbox et travaillé seulement dans la production. didRegisterForRemoteNotificationsWithDeviceToken est où j'inscris le deviceToken avec firebase. Comme cela ne se produisait pas, Firebase envoyait une charge utile avec la clé notification car elle ne savait pas que l'appareil était Apple. Aujourd'hui, Apple a résolu le problème et maintenant je peux envoyer des notifications.

+0

Merci Watson, c'est vraiment étrange, mais mon problème se produit toujours.J'utilise mon propre serveur pour envoyer APN atm. –

0

J'ai le même problème, j'ai ajouté la priorité 'haute' et ça a marché pour moi!

{ 
    "collapse_key" :"com.xxx.xxx", 
    to: "xxx", 
    priority : "high", 
    notification :{..} 
}