【发布时间】:2019-09-27 14:42:34
【问题描述】:
MOD - 我正在努力使用 APNs 服务在 iOS 设备上发送推送通知。 我的代码是:
try {
ApnsService apnsService =
APNS.newService()
.withCert(localCertPath, "psw")
//.withProductionDestination() --> why apns prod point at "gateway.push.apple.com", 2195 ???
.withGatewayDestination("api.push.apple.com", 443) --> is this right production endpoint? I think yes..reading official apple documentation
.build();
apnsService.start();
String payload = APNS.newPayload()
.alertBody("test notification")
.sound("default")
.build();
apnsService.push(DEVICE_TOKEN, payload);
System.out.println("Message sent!");
apnsService.stop();
} catch (NetworkIOException nE) {
nE.printStackTrace();
}
响应是 200 ok,但问题是:
Message sent!
2019-10-08 15:02:17.938+0200 [com.project.pushSender] INFO [Thread-9] [//] [c.n.a.i.ApnsConnectionImpl.run] - Exception while waiting for error code
java.io.IOException: Unexpected command byte 0
at com.notnoop.apns.internal.ApnsConnectionImpl$1MonitoringThread.run(ApnsConnectionImpl.java:118)
我也尝试过 curl,但它似乎发送了 0 字节的有效负载。
{ [5 bytes data]
* Connection state changed (MAX_CONCURRENT_STREAMS == 1000)!
} [5 bytes data]
* We are completely uploaded and fine
{ [5 bytes data]
HTTP/2 200
apns-id: xxx-XXX-xxx
{ [0 bytes data]
100 256 0 0 100 256 0 387 --:--:-- --:--:-- --:--:-- 387
* Connection #0 to host api.push.apple.com left intact
我正在尝试使用“com.notnoop.apns”库 1.0.0.Beta6(以及更低版本),但没有向设备发送任何通知。 也许我错了什么?
【问题讨论】:
标签: java ios spring push-notification apple-push-notifications