处理发送Parse PushNotification错误/超时

时间:2015-02-11 22:49:35

标签: java android parse-platform

对于我们尝试从与网络断开连接的设备发送推送通知的情况,是否有办法设置超时或获取错误???

我已经查看了API的文档,我也搜索了这个,但我找不到任何关于如何实现这一点。

例如,根据下面的代码,我们如何处理未发送推送通知的情况,因为此时设备没有网络连接? (相反,这段代码只是无声地失败我将回调传递给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...
        }                    
    }
});

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

铊组成; dr

当没有互联网时,

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 :(
        }                    
    }
});
相关问题