APNs请求返回200状态码但设备未收到推送通知排查求助
问题描述
按照Apple开发者文档《Send a Push Notification Using a Token》指引,执行以下curl命令调用APNs:
curl -v -H "apns-topic: pushnotify.com.xxxx.walletproject" -H "authorization: bearer xxxxx" -H "apns-id : eabexxxxx-xxxx-11e5-b60b-xxxxxxxx" -H "apns-push-type : alert" -H "apns-expiration : 0" -H "apns-priority : 10" --http2 --tlsv1.3 https://api.push.apple.com:2197/3/device/0a8163bxxxxxxxxxx -d '{"aps":{"alert":"hello xx"}}'
请求返回200状态码,但目标iPhone未收到推送通知(设备已开启所有通知权限),完整请求响应日志如下:
* Trying 17.188.171.97:2197... * Connected to api.push.apple.com (17.188.171.97) port 2197 (#0) * ALPN: offers h2,http/1.1 * TLSv1.3 (OUT), TLS handshake, Client hello (1): * CAfile: C:\curl-7.88.1_2-win64-mingw\bin\curl-ca-bundle.crt * CApath: none * TLSv1.3 (IN), TLS handshake, Server hello (2): * TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8): * TLSv1.3 (IN), TLS handshake, Request CERT (13): * TLSv1.3 (IN), TLS handshake, Certificate (11): * TLSv1.3 (IN), TLS handshake, CERT verify (15): * TLSv1.3 (IN), TLS handshake, Finished (20): * TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1): * TLSv1.3 (OUT), TLS handshake, Certificate (11): * TLSv1.3 (OUT), TLS handshake, Finished (20): * SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384 * ALPN: server accepted h2 * Server certificate: * subject: CN=api.push.apple.com; O=Apple Inc.; ST=California; C=US * start date: Dec 19 17:22:50 2022 GMT * expire date: Jan 18 17:22:49 2024 GMT * subjectAltName: host "api.push.apple.com" matched cert's "api.push.apple.com" * issuer: CN=Apple Public Server RSA CA 12 - G1; O=Apple Inc.; ST=California; C=US * SSL certificate verify ok. * using HTTP/2 * h2h3 [:method: POST] * h2h3 [:path: /3/device/0a8163bxxxxxxxxxx] * h2h3 [:scheme: https] * h2h3 [:authority: api.push.apple.com:2197] * h2h3 [user-agent: curl/7.88.1] * h2h3 [accept: */*] * h2h3 [apns-topic: pushnotify.com.xxxx.walletproject] * h2h3 [authorization: bearer xxxxx] * h2h3 [apns-id : eabexxxxx-xxxx-11e5-b60b-xxxxxxxx] * h2h3 [apns-push-type : alert] * h2h3 [apns-expiration : 0] * h2h3 [apns-priority : 10] * h2h3 [content-length: 24] * h2h3 [content-type: application/x-www-form-urlencoded] * Using Stream ID: 1 (easy handle 0x1f0fa3eba90) > POST /3/device/0a8163bxxxxxxxxxx HTTP/2 > Host: api.push.apple.com:2197 > user-agent: curl/7.88.1 > accept: */* > apns-topic: pushnotify.com.xxxx.walletproject > authorization: bearer xxxx > apns-id : eabexxxxx-xxxx-11e5-b60b-xxxxxxxx > apns-push-type : alert > apns-expiration : 0 > apns-priority : 10 > content-length: 24 > content-type: application/x-www-form-urlencoded > * We are completely uploaded and fine * TLSv1.3 (IN), TLS handshake, Newsession Ticket (4): * TLSv1.3 (IN), TLS handshake, Newsession Ticket (4): * old SSL session ID is stale, removing < HTTP/2 200 < apns-id: xxxxxx-xxxxx-xxxxx-DD7A-xxxxxxx < * Connection #0 to host api.push.apple.com left intact
可能的问题原因及排查方向
- 设备令牌有效性问题:确认设备令牌
0a8163bxxxxxxxxxx是否为当前设备的最新有效令牌。设备令牌会在应用重装、系统升级后变更,需确保使用的是应用启动时最新获取的令牌。 - APNs环境不匹配:如果是测试设备,应该使用沙箱环境地址
https://api.development.push.apple.com:2197,而非生产环境的api.push.apple.com。检查当前调用的环境是否与设备安装的应用版本(开发版/生产版)对应。 - 请求头格式问题:日志中显示部分请求头存在多余空格,比如
apns-id :、apns-push-type :等,尽管APNs可能兼容,但建议严格按照规范去掉冒号后的空格,避免潜在解析问题。 - 推送内容格式错误:
- 当前请求的
content-type为application/x-www-form-urlencoded,但推送JSON payload必须使用application/json,这会导致APNs无法正确解析内容,即使返回200也不会推送通知。 - 确认
aps结构是否符合规范,可尝试添加"sound": "default"字段,确保alert类型推送的完整性。
- 当前请求的
- 设备状态限制:
- 检查设备是否处于联网状态,部分网络可能屏蔽2197端口导致APNs无法送达。
- 确认设备是否开启了“专注模式”或“勿扰模式”,这类模式会静默通知。
- 再次前往iPhone的「设置」-「通知」-「对应应用」,确认所有通知权限(包括横幅、声音、通知中心显示等)均已开启,且未设置为“静默通知”。
- 授权令牌问题:验证
authorization中的bearer令牌是否有效,是否与apns-topic对应的App ID匹配,且令牌未过期。可重新生成JWT令牌后再次尝试。 - APNs延迟问题:部分情况下,APNs返回200后可能因网络负载出现延迟,可等待3-5分钟后再检查设备是否收到通知。
内容的提问来源于stack exchange,提问作者huMpty duMpty
相关产品推荐
相关产品推荐

