Ionic Push Notification 在生产中甚至没有发送到 iOS(更不用说收到了)

Ionic Push Notification not even sent to iOS (let alone received) on production

我在生产模式下 iOS 的推送通知有问题。

我第一次开发Push for development:

Android 和 iOS 都工作正常。


然后我切换到生产:


我总是使用 Postman 测试 Push:

发送 POSThttps://api.ionic.io/push/notifications 正文:

{
    "tokens": [
        "<ios token>",
        "<android token>"
    ],
    "profile": "live",
    "notification": {
        "message": "test",
        "ios": {
            "priority": 10
        },
        "android": {
            "priority": "high"
        }
    }
}

回复:

{
  "data": {
    "status": "open",
    "config": {
      "profile": "live",
      "notification": {
        "android": {
          "priority": "high"
        },
        "ios": {
          "priority": 10
        },
        "message": "test"
      },
      "tokens": [
        "<ios token>",
        "<android token>"
      ]
    },
    "created": "2017-02-14T15:07:58.988762+00:00",
    "app_id": "<app id>",
    "uuid": "<uuid>",
    "state": "enqueued"
  },
  "meta": {
    "status": 201,
    "request_id": "<request id>",
    "version": "2.0.0-beta.0"
  }
}


要查看发生了什么,我总是在之后发送 GEThttps://api.ionic.io/push/notifications/<uuid>/messages uuid来自第一个响应) 并得到以下响应:

{
  "data": [
    {
      "status": "sent",
      "created": "2017-02-14T15:07:59.165266+00:00",
      "user_id": null,
      "token": {
        "token": "<android token>",
        "valid": true,
        "type": "android",
        "app_id": "<app id>",
        "invalidated": null,
        "id": "<id>",
        "created": "2017-02-14T14:27:27.585235+00:00"
      },
      "error": null,
      "notification": "<notification uuid>",
      "uuid": "<message uuid>"
    }
  ],
  "meta": {
    "status": 200,
    "request_id": "<request id>",
    "version": "2.0.0-beta.0"
  }
}

我注意到响应中缺少相应 <ios token> 的数据。
我想知道为什么连 Ionic Docs.
中列出的错误响应都没有 如果我使用 dev 安全配置文件发送两个请求,我会得到 iOS 的数据,说明“error” (APNS_BAD_DEVICE_TOKEN) - 这是正确的。

我已经尝试重新创建证书和内容,这不会改变结果。我还等了一整天才收到通知,以防万一需要很长时间。我再次确保我在 Xcode.

中使用正确的配置文件构建了应用程序

顺便说一句,我正在使用 Xcode 8.2 - 并且明确确保在功能中启用“推送通知”。

我错过了什么?

联系 Ionic 支持后,他们提出了检查令牌是否有效的想法。

操作方法记录在 their docs:

(GET) https://api.ionic.io/push/tokens/:token_id(其中 token_id 是设备令牌的 md5 哈希值)

我在 Postman 中添加了一个预请求脚本,例如:

var token = "<your-device-token-to-check>";
var hash = CryptoJS.MD5( token ).toString();
postman.setEnvironmentVariable('token_hash', token);

... 并将新环境变量添加为参数(不在请求 URL 中)作为 key: (leave empty); value: ":{{token_hash}}"

然后我发现,我所有的 iOS 令牌在注册后不久就失效了。这就是我们第一次测试成功并在进一步开发中突然失败的原因。
我不知道为什么在检查 Ionic API 的通知状态时,他们会被排除在响应之外。我建议支持添加一个错误响应(据我所知,已经有一个:'APNS_BAD_DEVICE_TOKEN' as "The specified device token was bad. Verify that you specified a valid token [...]".)


因为我无法解释原因,我只是重新创建了新的配置文件和证书(再次!),并从 Mac 上的钥匙串访问中删除了旧的。我重新构建了应用程序,一切正常。奇怪...