2011-09-06 86 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。