ios apn push - pushy测试

参照文档

https://github.com/jchambers/pushy

按照上面的步骤一步步来.

首先添加pom依赖,刷新maven下载对应的包体;

向公司的管理这索取当前用来测试的.p12文件和对应的密码,和申请时的topic,填到代码中就可以了.

特别注意topic和密码和p12文件都对.

然后去对应的用户中找合适token用户测试正对这个用户的push,看到苹果反馈accepted就可以了.

 

详细代码如下:


    public static void main(String[] argv) throws Exception {
        
        final ApnsClient apnsClient = new ApnsClientBuilder()
                .setApnsServer(ApnsClientBuilder.PRODUCTION_APNS_HOST)
                .setClientCredentials(new File("D:/codes/Codes/DoomsdayServer1.0/conf/XXXXX.p12"), "xxxxx")
                .build();

        final SimpleApnsPushNotification pushNotification;

        {
            final ApnsPayloadBuilder payloadBuilder = new SimpleApnsPayloadBuilder();
            payloadBuilder.setAlertBody("Example!~~~");
            payloadBuilder.setAlertTitle("ex");
            payloadBuilder.setLocalizedAlertTitle("Open App");


            final String payload = payloadBuilder.build();
            final String token = TokenUtil.sanitizeTokenString("xxxxxx");

            pushNotification = new SimpleApnsPushNotification(token, "com.abc.def", payload);
        }


        final PushNotificationFuture<SimpleApnsPushNotification, PushNotificationResponse<SimpleApnsPushNotification>>
                sendNotificationFuture = apnsClient.sendNotification(pushNotification);


        try {
            final PushNotificationResponse<SimpleApnsPushNotification> pushNotificationResponse =
                    sendNotificationFuture.get();

            if (pushNotificationResponse.isAccepted()) {
                System.out.println("Push notification accepted by APNs gateway.");
            } else {
                System.out.println("Notification rejected by the APNs gateway: " +
                        pushNotificationResponse.getRejectionReason());

                pushNotificationResponse.getTokenInvalidationTimestamp().ifPresent(timestamp -> {
                    System.out.println("\t…and the token is invalid as of " + timestamp);
                });
            }
        } catch (final ExecutionException e) {
            System.err.println("Failed to send push notification.");
            e.printStackTrace();
        }

        try {
            final CompletableFuture<Void> closeFuture = apnsClient.close();
        } catch (final Exception e) {
            System.err.println("Failed to send push notification.");
            e.printStackTrace();
        }
    }

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值