用Pushy for java发送apn通知

时间:2014-09-11 15:04:44

标签: java push-notification apple-push-notifications

我向Pushy(用于发送APN的Java库)发送一些推送通知到iPhone设备。

我们仍然在沙盒中测试它。奇怪的问题是,3天前一切正常,通知到达手机,但从今天开始,没有任何消息传递。代码没有改变,我的java代码中没有例外。

我还仔细检查了证书是否正确以及设备令牌是否正确。

我已经注册了两个:

  • RejectedNotificationListener
  • FailedConnectionListener

但是听众中没有例外。

有没有办法检查已发送邮件的内容?

如果我为pushy启用调试模式,我在日志中看到:

17:49:17,054 INFO  [com.relayrides.pushy.apns.PushManager] (default task-2) Push manager starting.
17:49:17,054 DEBUG [com.relayrides.pushy.apns.ApnsConnection] (default task-2) ApnsConnection-1 beginning connection process.
17:49:17,344 DEBUG [com.relayrides.pushy.apns.ApnsConnection] (nioEventLoopGroup-3-1) ApnsConnection-1 connected; waiting for TLS handshake.
17:49:17,743 DEBUG [com.relayrides.pushy.apns.ApnsConnection] (nioEventLoopGroup-3-1) ApnsConnection-1 successfully completed TLS handshake.
17:49:17,744 TRACE [com.relayrides.pushy.apns.PushManager] (nioEventLoopGroup-3-1) Connection succeeded: ApnsConnection [name=ApnsConnection-1]
17:49:17,745 TRACE [com.relayrides.pushy.apns.ApnsConnection] (nioEventLoopGroup-3-1) ApnsConnection-1 sending SendableApnsPushNotification [sequenceNumber=0, token=******************************, payload={"eventId":"212121","aps":{"alert":"It's alive :)","sound":"ring-ring.aiff"}}, deliveryInvalidation=null]
17:49:17,747 TRACE [com.relayrides.pushy.apns.ApnsConnection] (nioEventLoopGroup-3-1) ApnsConnection-1 successfully wrote notification 0
17:49:22,061 INFO  [com.relayrides.pushy.apns.PushManager] (default task-2) Push manager shutting down.
17:49:22,061 DEBUG [com.relayrides.pushy.apns.ApnsConnection] (nioEventLoopGroup-3-1) ApnsConnection-1 sending known-bad notification to shut down.
17:49:22,062 TRACE [com.relayrides.pushy.apns.ApnsConnection] (nioEventLoopGroup-3-1) ApnsConnection-1 successfully wrote known-bad notification 1
17:49:22,239 DEBUG [com.relayrides.pushy.apns.ApnsConnection] (nioEventLoopGroup-3-1) APNs gateway rejected notification with sequence number 1 from ApnsConnection-1 (MISSING_TOKEN).
17:49:22,240 TRACE [com.relayrides.pushy.apns.PushManager] (nioEventLoopGroup-3-1) Connection closed: ApnsConnection [name=ApnsConnection-1]

这是我的代码:

try{

            final PushManagerFactory<SimpleApnsPushNotification> pushManagerFactory =
                    new PushManagerFactory<SimpleApnsPushNotification>(ApnsEnvironment.getSandboxEnvironment(),
                            PushManagerFactory.createDefaultSSLContext("*********.p12", "******"));

            final PushManager<SimpleApnsPushNotification> pushManager =  pushManagerFactory.buildPushManager();

            pushManager.start();

            pushManager.registerRejectedNotificationListener(new AppleRejectedNotificationListener());
            pushManager.registerFailedConnectionListener(new AppleFailedConnectionListener());

            final byte[] token = TokenUtil.tokenStringToByteArray("**********************");

            final ApnsPayloadBuilder payloadBuilder = new ApnsPayloadBuilder();

            payloadBuilder.addCustomProperty("eventId", "212121");
            payloadBuilder.setAlertBody("It's alive :)");
            payloadBuilder.setSoundFileName("ring-ring.aiff");

            final String payload = payloadBuilder.buildWithDefaultMaximumLength();

            pushManager.getQueue().put(new SimpleApnsPushNotification(token, payload));

            pushManager.shutdown();

        } catch (Exception e){
            log.error("",e);
        }

0 个答案:

没有答案