使用notnoop / java-apns发送消息:消息已发送...但我收到一些错误

时间:2013-05-02 20:43:37

标签: ios apple-push-notifications

使用notnoop / java-apns https://github.com/notnoop/java-apns我正在使用此代码发送消息:

try {
ApnsService service = APNS
.newService()
.withCert("myCertificates.p12",
"xxxxxxxxxx").withProductionDestination().build();

        String payload = APNS.newPayload().alertBody(messageObject.MsgText)
                .sound("default").badge(1).build();

        Iterator<String> vItr = messageObject.addresses.iterator();
        while (vItr.hasNext()) {
            String sent2Token = (String) (vItr.next());

            service.push(sent2Token, payload);
        }
        service.stop();

    } catch (NetworkIOException e) {
        System.out.println("client>> " + e.getMessage());
        e.printStackTrace();
    }

消息发送正常,但需要获取此输出的红色,因为它可能会减慢我的程序旁边占用空间....请建议吗?

16:07:56.206 [Thread-4140] INFO c.n.apns.internal.ApnsConnectionImpl - Exception while waiting for error code
java.net.SocketException: Socket closed
at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.7.0_05]
at java.net.SocketInputStream.read(SocketInputStream.java:150) ~[na:1.7.0_05]
at java.net.SocketInputStream.read(SocketInputStream.java:121) ~[na:1.7.0_05]
at sun.security.ssl.InputRecord.readFully(InputRecord.java:312) ~[na:1.7.0_05]
at sun.security.ssl.InputRecord.read(InputRecord.java:350) ~[na:1.7.0_05]
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:893) ~[na:1.7.0_05]
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:850) ~[na:1.7.0_05]
at sun.security.ssl.AppInputStream.read(AppInputStream.java:102) ~[na:1.7.0_05]
at java.io.InputStream.read(InputStream.java:101) ~[na:1.7.0_05]
at com.notnoop.apns.internal.ApnsConnectionImpl$1MonitoringThread.run(ApnsConnectionImpl.java:122) ~[server.jar:na]

1 个答案:

答案 0 :(得分:1)

要复活一年前的问题:

直到最近,当与apns服务的连接关闭时,java-apns才会记录异常。你应该做两件事:

  • 使用不记录该异常的java-apns 1.0.0 Beta2(在maven central上可用)
  • 通常,您在服务器运行期间保持构建的ApnsService,因为设置和关闭SSL连接有点贵。因此,只有在确定您未能长时间发送其他连接时才关闭它。 ApnsService与Apple的推送服务器保持实时连接。