【发布时间】:2019-04-30 06:25:18
【问题描述】:
我在 ios firebase 推送通知中遇到了一个奇怪的问题。每当我从 Xcode 运行应用程序时,甚至当我创建存档时,我都会在设备上收到通知,我也成功收到了通知。
但是当我在设备上运行发布版本或上传到应用商店时,推送通知对我不起作用,我收到以下错误
开发和生产证书均已上传且有效。
{
"multicast_id": 6319718121948146737,
"success": 0,
"failure": 1,
"canonical_ids": 0,
"results": [
{
"error": "InvalidRegistration"
}
]
}
当我第二次使用相同的令牌调用 API 而不是 InvalidRegistration 时,我得到了 NotRegistered 错误
这就是我生成 fcm 令牌的方式
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,但这似乎是沙盒/生产问题,请告诉我此链接是否有帮助 stackoverflow.com/a/54175003/6330448,您也可以参考此问题 stackoverflow.com/questions/41169460/…
-
我之前已经关注了您的第二个链接,但仍然没有帮助。我也是这样的
-
尝试在没有私钥的情况下创建生产证书,这里没有您遗漏的任何内容。
-
我尝试使用 APNs 证书向我的 APNs 设备令牌发送通知,但它给了我无效的设备令牌,但在沙盒环境中它工作得非常好@dreamBegin
-
是的,我在大多数问题中看到的,因为他们用私钥在那里导入证书,你试过排除你的私钥吗?
标签: ios firebase push-notification firebase-cloud-messaging