简体   繁体   English

Firebase消息传递iOS:usersInfo为空或我从没收到通知

[英]Firebase messaging iOS : usersInfo is empty or I never get the notification

I follow the rules from the Google Firebase for configuring my iOS app. 我遵循Google Firebase的规则配置我的iOS应用。 When I give to the Firebase Console a Device ID (token) which has never been used, the notification is caught by my app, but the userInfo is empty: 当我向Firebase控制台提供一个从未使用过的设备ID(令牌)时,该通知会被我的应用捕获,但userInfo为空:

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"]!)") /* HERE */

    // Print full message.
    print("%@", userInfo)
}

On the line with the /* HERE */ comment, the app crashes because userInfo is nil . 在带有/* HERE */注释的行上,由于userInfo为nil ,应用程序崩溃。

When I try again another notification from the Firebase console, the notification is not caught and nothing appends (I have a breakpoint in the reception notification function). 当我从Firebase控制台再次尝试另一个通知时,未捕获到该通知,并且未追加任何内容(接收通知功能中有一个断点)。

What's wrong ? 怎么了 ?

Make sure you are using the Firebase token that is generated and not the device token that made this mistake. 确保您使用的是生成的Firebase令牌,而不是使用导致此错误的设备令牌。 You will need to put this in your code to get the token you need: 您将需要将此代码放入代码中以获得所需的令牌:

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

I put this inside of my code: 我把它放在我的代码中:

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未收到通过 iOS 应用程序中的 firebase 云功能发送的推送通知,尽管我从消息控制台获取 - Not receiving push notification sent via firebase cloud functions in iOS app though I get the from messaging console 在 iOS 上未收到 Firebase 云消息传递通知 - Firebase Cloud Messaging notification not received on iOS Firebase Cloud Messaging iOS:无后台推送通知 - Firebase Cloud Messaging iOS: No background push notification Firebase 云消息未收到通知 (iOS) - Firebase Cloud Messaging Not Receiving Notification (iOS) 使用新的Firebase Messaging SDK在iOS中进行通知 - Notification in iOS using new Firebase Messaging SDK 如何从iOS上的Firebase Cloud Messaging获取令牌 - How can I get the token from Firebase Cloud Messaging on iOS Flutter/ios:无法让 firebase 消息传递工作 - Flutter/ios: Cant get firebase messaging to work Flutter FCM 推送通知未在 IOS 上接收到 firebase_messaging:^9.1.3 - Flutter FCM push notification not receiving on IOS with firebase_messaging: ^9.1.3 如何使用Firebase Cloud Messaging自动增加iOS通知徽章? - How to auto increment iOS notification badge with Firebase Cloud Messaging? 无法将通知发送到iOS(iPhone)Firebase云消息传递 - Can Not Send Notification to iOS (iPhone) Firebase Cloud Messaging
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM