2011-09-06 85 views
1

我正在为项目发送通知给iPhone。我用javapns。但是当我invork消息:javapns中使用的CPU 100%

pushManager.sendNotification(client, complexPayLoad); 

我发现邮件无法正确地返回,并导致CPU使用率达到100%。 有人可以告诉我哪里错了我的代码?谢谢。

更completement代码

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()); 
    } 
+0

我检查javapns的源代码。我发现我在sendNotification方法中挂在这里:'logger.debug(“Notification sent”); logger.debug(“In:[”+ in.readLine()+“]”); while(!this.socket.isInputShutdown()){while(in.ready()){logger.debug(“ready now”); logger.debug(in.readLine()); System.out.println(this.socket.getInputStream()。read()); }}' – Apollo

回答

0

什么版本?

版本2刚刚出来,并修复了一些问题。

它也容易实现。

+0

感谢您的评论。我的版本是1.6.9。是的,当我在javapns 2.0测试版下测试时没关系。但似乎无法正确支持http代理。 – Apollo

0

我在javapns的bug列表上找到一个解决方案,另请参阅:javapns issue48,它修复了http代理错误,并且在发送通知消息时不会导致100%cpu。