Firebase云消息传递将消息发送到iid导入的Apns令牌

时间:2018-06-29 15:19:37

标签: ios firebase firebase-cloud-messaging

我正在编写一个应从服务器向Android和iOS设备发送推送通知的应用程序。我尝试将FCM用于此目的。 iOS应用程序使用APNS,因此我可以在服务器端获取apns订阅令牌。然后,我尝试batch import这些令牌,我获得了某种长度为174个符号的注册令牌,而不是Firebase中通常使用的152个符号。 当我使用IID方法GET https://iid.googleapis.com/iid/info/ {token}时,它会成功返回有关给定令牌的信息,但是当我尝试使用HTTP v1 API POST https://fcm.googleapis.com/v1/projects/ {0} / messages直接使用此令牌发送消息时:使用目标字段"token":"f5MpeWlqg0E:APA91bHGpRR3_ygt10....CdI3Rtsodf8XMIQNlflF23mQ"和ios特定的有效负载发送方法,出现错误:

{   
    "error": {
    "code": 400,
    "message": "Request contains an invalid argument.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.firebase.fcm.v1.FcmError",
        "errorCode": "INVALID_ARGUMENT"
      },
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "field": "message.token",
            "description": "Invalid registration token"
          }
        ]
      }
    ]   
   } 
}

然后,如果我尝试再次将相同的消息发送到相同的令牌,则会收到另一个错误:

{
  "error": {
    "code": 404,
    "message": "Requested entity was not found.",
    "status": "NOT_FOUND",
    "details": [
      {
        "@type": "type.googleapis.com/google.firebase.fcm.v1.FcmError",
        "errorCode": "UNREGISTERED"
      }
    ]
  }
}

并且IID方法也返回404,这意味着Firebase从系统中删除了我的令牌。 问题是,为什么我会从无法解决的IID中获得“错误”令牌,以及如何向iOS手机发送直接通知。

1 个答案:

答案 0 :(得分:0)

好吧,问题出在iid设置中:当我尝试从APNS令牌中检索FCM令牌时,我将“ sandbox”设置为false,但是使用了沙盒证书,因此该令牌无效。