[英]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.