• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

java - 在 APNS 服务器中知道未注册 token 的方法(使用 Spring Server)

[复制链接]
菜鸟教程小白 发表于 2022-12-12 10:14:49 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

在 android 中成功完成推送通知。现在处理 ios 推送通知。

gcm服务器推送通知的情况下,服务器通知 token 未注册或无效等。同样有任何方法可以进入apns服务器。 p>

请检查我的代码以在 APNS

中发送推送通知
 public void pushMessage() {
        ApnsService service = null;
        try {
            // get the certificate
            InputStream certStream = this.getClass().getClassLoader().getResourceAsStream("your_certificate.p12");
            service = APNS.newService().withCert(certStream, "your_cert_password").withSandboxDestination().build();
            // or
            // service = APNS.newService().withCert(certStream,
            // "your_cert_password").withProductionDestination().build();
            service.start();
             // read your user list
            List<User> userList = userDao.readUsers();
            for (User user : userList) {
                try {
                    // we had a daily update here, so we need to know how many 
                    //days the user hasn't started the app
                    // so that we get the number of updates to display it as the badge.
                    int days = (int) ((System.currentTimeMillis() - user.getLastUpdate()) / 1000 / 60 / 60 / 24);
                    PayloadBuilder payloadBuilder = APNS.newPayload();
                    payloadBuilder = payloadBuilder.badge(days).alertBody("some message you want to send here");
                    // check if the message is too long (it won't be sent if it is) 
                    //and trim it if it is.
                    if (payloadBuilder.isTooLong()) {
                        payloadBuilder = payloadBuilder.shrinkBody();
                    }
                    String payload = payloadBuilder.build();
                    String token = user.getToken();
                    service.push(token, payload);
                } catch (Exception ex) {
                    // some logging stuff
                }
            }
        } catch (Exception ex) {
            // more logging
        } finally {
            // check if the service was successfull initialized and stop it here, if it was
            if (service != null) {
                service.stop();
            }

        }
    }

我使用 com.notnoop.apns 库发送 APNS 推送通知。



Best Answer-推荐答案


您必须从列表中删除不再使用的设备,请使用以下代码

Map<String, Date> inactiveDevices = service.getInactiveDevices();
            for (String deviceToken : inactiveDevices.keySet()) {
               // delete from table
            }

这里的serviceApnsService的对象。

ApnsService service;

关于java - 在 APNS 服务器中知道未注册 token 的方法(使用 Spring Server),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34915399/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap