2015-02-11 36 views
0

有沒有一種方法來設置超時或以獲取我們試圖從從網絡斷開連接的設備發送推送通知的情況下,錯誤???處理髮送解析PushNotification錯誤/超時

我找遍了整個API的文檔上,我也用Google搜索這個,但我無法找到如何做到這一點任何東西。

例如,假設下面的代碼,我們如何能處理的,因爲,在那一刻,該設備沒有網絡連接的推送通知未發送的情況下? (相反,這段代碼只是默默地失敗我閹傳遞迴調到sendInBackground與否,ParseException的參數是總是空...)

ParsePush push = new ParsePush(); 
push.setMessage("Test..."); 
push.setQuery(someParseQuery); 
push.sendInBackground(new SendCallback(){ 
    @Override 
    public void done(ParseException e) { 
     // TODO Auto-generated method stub 
     if(e == null){ 
      //it always gets here, even if device has no connectivity... 
     } else { 
      //never enters here when there is no network connectivity... 
     }      
    } 
}); 

將非常感謝您的幫助!

回答

0

文藝青年最愛的

SendCallBack犯規養ParseException的時候沒有互聯網存在,因此,根本不可能以檢查是否推實際上已發送或沒有。解決方法是編寫一個包裝器或某種類型的服務器來檢查互聯網連接是否存在,然後發送推送,但這樣的解決方案遠非理想。

////////////////////////////////////////////// /////////////////////////////////////

你不能給

push.sendInBackground(); 

處理推送返回的處理程序?

sendInBackground

public void sendInBackground(SendCallback callback) 

Sends this push notification in a background thread. 
This is preferable to using send(), unless your code is already running from a background thread. 

Parameters: 
callback - callback.done(e) is called when the send completes.      

示例代碼:

push.sendInBackground(new SendCallback(){ 
    @Override 
    public void done(ParseException e) { 
     // TODO Auto-generated method stub 
     if(e == null){ 
      //Succesfully send your pushnotification 
     } else { 
      //Oh uh, something went wrong :(
     }      
    } 
}); 
+0

感謝巴特,但不得傳遞處理的sendInBackground不工作,因爲ParseException的總是空(即「全成「),即使推送通知發送時沒有網絡連接... – 2015-02-11 23:28:43

+0

嗯,這是一個恥辱,我由於ParseException有一個枚舉CONNECTION_FAILED,因此連接到Parseservers失敗時,預計它會拋出一個期望。 – 2015-02-11 23:41:57

+0

是的,我希望那樣做,但我已經多次測試過,並且證實這個異常總是空的......但是也許我正在做一些非常錯誤的事情......它對你有用嗎? – 2015-02-11 23:48:49