iOS发布版本中的FCM InvalidRegistration错误

时间:2019-04-30 06:25:18

标签: ios firebase push-notification firebase-cloud-messaging

我在ios firebase推送通知中面临一个奇怪的问题。每当我从Xcode运行应用程序时,甚至在创建档案时,我都会在设备上收到通知,我成功地收到了通知。

但是当我在设备上运行发布版本或上传到应用商店时,推送通知对我不起作用,并且出现以下错误

用于开发和生产的证书已上传且有效。

InvalidRegistration

第二次使用相同令牌调用API时,而不是NotRegistered出现func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) { print("Firebase registration token: \(fcmToken)") } func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { // Pass device token to auth #if DEVELOPMENT Auth.auth().setAPNSToken(deviceToken, type: .sandbox) Messaging.messaging().setAPNSToken(deviceToken, type: .sandbox) #else Auth.auth().setAPNSToken(deviceToken, type: .prod) Messaging.messaging().setAPNSToken(deviceToken, type: .prod) #endif Messaging.messaging().apnsToken = deviceToken Messaging.messaging().shouldEstablishDirectChannel = true //tried this let token = Messaging.messaging().fcmToken print("Firebase registration token: \(token)") //tried this also both are giving same token but none of them is //working in release build let refreshedToken = InstanceID.instanceID().token() print("InstanceID token: \(refreshedToken)") } 错误

这就是我生成fcm令牌的方式

{{1}}

1 个答案:

答案 0 :(得分:0)

最后,我通过从代码中删除这一部分来解决了这个问题

 #if DEVELOPMENT
 Auth.auth().setAPNSToken(deviceToken, type: .sandbox        
 Messaging.messaging().setAPNSToken(deviceToken, type: .sandbox)
 #else
 Auth.auth().setAPNSToken(deviceToken, type: .prod)
 Messaging.messaging().setAPNSToken(deviceToken, type: .prod)
 #endif