javapns 中 CPU 使用率 100%

发布于 2024-12-03 05:46:03 字数 1295 浏览 2 评论 0原文

我正在从事一个向 iPhone 发送通知的项目。我用的是javapns。但是当我调用该消息时:

pushManager.sendNotification(client, complexPayLoad);

我发现该消息无法正确返回,并且导致CPU使用率变为100%。 谁能告诉我我的代码哪里出了问题?谢谢。

更多完整代码

try {
        // create a complex PayLoad with a custom alert
        PayLoad complexPayLoad = new PayLoad();
        PayLoadCustomAlert customAlert = new PayLoadCustomAlert();
        customAlert.addBody(message);
        complexPayLoad.addCustomAlert(customAlert);
        complexPayLoad.addSound("chime");
        for (String key : new HashSet<String>(data.keySet())) {
            complexPayLoad.addCustomDictionary(key, (String)data.get(key));
        }

        try {
            // Link iPhone's UDID (64-char device token) to a stringName
            pushManager.addDevice(token, token);
        } catch (Exception ex) {
            // Perhaps we added duplicate devices
            log.debug("Perhaps we added duplicate devices");
        }

        // Get iPhone client
        Device client = pushManager.getDevice(token);

        // Send message
        pushManager.sendNotification(client, complexPayLoad);
        log.info("Message sent!"); // i cannot get this message

    } catch (Exception e) {
        log.error(e.getMessage());
    }

i'm working for a project send notification to iPhone. and i used javapns. but when i invork the message:

pushManager.sendNotification(client, complexPayLoad);

i found the message cannot return correctly, and it cause cpu usage become 100%.
could anybody tell me where's wrong about my code? Thanks.

more completement code

try {
        // create a complex PayLoad with a custom alert
        PayLoad complexPayLoad = new PayLoad();
        PayLoadCustomAlert customAlert = new PayLoadCustomAlert();
        customAlert.addBody(message);
        complexPayLoad.addCustomAlert(customAlert);
        complexPayLoad.addSound("chime");
        for (String key : new HashSet<String>(data.keySet())) {
            complexPayLoad.addCustomDictionary(key, (String)data.get(key));
        }

        try {
            // Link iPhone's UDID (64-char device token) to a stringName
            pushManager.addDevice(token, token);
        } catch (Exception ex) {
            // Perhaps we added duplicate devices
            log.debug("Perhaps we added duplicate devices");
        }

        // Get iPhone client
        Device client = pushManager.getDevice(token);

        // Send message
        pushManager.sendNotification(client, complexPayLoad);
        log.info("Message sent!"); // i cannot get this message

    } catch (Exception e) {
        log.error(e.getMessage());
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

澉约 2024-12-10 05:46:03

什么版本?

版本 2 刚刚发布,修复了一些问题。

它也更容易实施。

What version?

Version 2 just came out, and fixed a number of issues.

It is also much easier to implement.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文