我正在为一个项目发送通知到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());
}
最佳答案
什么版本的?
版本2刚刚发布,并修复了许多问题。
实施起来也容易得多。