简体   繁体   English

Firebase Cloud Messaging 返回 InvalidApnsCredential 尽管存在有效的 P8 APNs 授权密钥

[英]Firebase Cloud Messaging returning InvalidApnsCredential despite valid P8 APNs Auth Key existing

I am trying to send notifications to an IOS device using Firebase Cloud Messaging - every IOS project in the Firebase Console has a valid APNs P8 Auth Key, freshly generated from the Apple developer account for this purpose.我正在尝试使用 Firebase Cloud Messaging 向 IOS 设备发送通知 - Firebase 控制台中的每个 IOS 项目都有一个有效的 APNs P8 Auth Key,为此目的从 Apple 开发者帐户新生成。

I'm using this approach:我正在使用这种方法:

curl -X POST \
  https://fcm.googleapis.com/fcm/send \
  -H 'Authorization: key=<My Key>' \
  -H 'Content-Type: application/json' \
  -H 'cache-control: no-cache' \
  -d '{
    "to": "<Device Token>",
    "notification": {
        "title": "Push Notification Test to IOS",
        "body":"Push Notification Test to IOS"
    },
    "data": {
        "message": "Push Notification Test to IOS"
    }
}'

This results in the following error from FCM:这会导致 FCM 出现以下错误:

{
    "multicast_id": <Id>,
    "success": 0,
    "failure": 1,
    "canonical_ids": 0,
    "results": [
        {
            "error": "InvalidApnsCredential"
        }
    ]
}

If I remove the "notification" block from the message, FCM responds with a success, but nothing is received on the device.如果我从消息中删除“通知”块,FCM 会成功响应,但设备上不会收到任何消息。

I can send and receive notifications using the above example message to Android devices just fine.我可以使用上面的示例消息向 Android 设备发送和接收通知。

The FCM documentation suggests that when a "notification" block is included, FCM attempts to send via APNs when the token is for an IOS device: FCM 文档建议当包含“通知”块时,当令牌用于 IOS 设备时,FCM 会尝试通过 APNs 发送:

If a notification payload is provided, or the content_available option is set to true for a message to an iOS device, the message is sent through APNs, otherwise it is sent through the FCM connection server.如果提供了通知负载,或者将消息的 content_available 选项设置为 true 以发送到 iOS 设备,则消息将通过 APNs 发送,否则将通过 FCM 连接服务器发送。

What I have tried:我试过的:

  • Refreshing the tokens刷新令牌
  • Waiting 24 hours for tokens to propagate in APNs and FCM server environments等待 24 小时让令牌在 APNs 和 FCM 服务器环境中传播
  • using P12 certificates使用 P12 证书
  • using P8 certificates使用 P8 证书
  • ensured the IOS app is allowing notifications in Xcode确保 IOS 应用允许 Xcode 中的通知
  • ensured the Apple Developer account has the app as allowing notifications确保 Apple Developer 帐户具有允许通知的应用程序
  • ensured the Bundle Ids are correct in the plist, FCM and Apple account确保 plist、FCM 和 Apple 帐户中的 Bundle Id 正确
  • tried both the FCM legacy key and server key尝试了 FCM 遗留密钥和服务器密钥

I had the same problem and then I create a P8 file and upload it to firebase in your project and start working the notification field 我遇到了同样的问题,然后创建了一个P8文件并将其上传到您项目中的firebase并开始处理通知字段

Link in portuguese How to install the P8 file to firebase 葡萄牙语链接如何将P8文件安装到Firebase

InvalidApnsCredential doesn't means the issue is directly related to the APNS certificate nor the key. InvalidApnsCredential并不意味着问题与 APNS 证书或密钥直接相关。

I my case, I faced this problem with a white labeled app & after investigation, I found that my app bundle id (PRODUCT_BUNDLE_IDENTIFIER) was not matching the one in Firebase (I was using a development bundle id instead of the production one).我的情况是,我遇到了这个带有白色标签应用程序的问题,经过调查,我发现我的应用程序包 ID (PRODUCT_BUNDLE_IDENTIFIER) 与 Firebase 中的不匹配(我使用的是开发包 ID 而不是生产包 ID)。

Make sure that your Bundle ID is correct.确保您的 Bundle ID 是正确的。

If it's not the same, create a new iOS app ( ConfigurationGeneralAdd an app ) and make sure to set the name correctly.如果不一样,请创建一个新的 iOS 应用程序(配置常规添加应用程序)并确保正确设置名称。

In my case, I had the shortest version of the bundle ID ( com.company ) instead of the long one ( com.company.appname ).在我的例子中,我有最短版本的包 ID ( com.company ) 而不是长版本 ( com.company.appname )。

Doing this you should not need to re-compile and re-upload the app.这样做你不需要重新编译和重新上传应用程序。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM