cordova / phonegap推送通知unregister()即使关闭互联网也会返回成功

时间:2015-01-08 17:58:18

标签: android ios cordova notifications

我正在使用Phonegap推送插件(https://github.com/phonegap-build/PushPlugin)并具有以下功能(以及成功和错误回调),当我通过切换关闭通知时调用该功能

function pushNotificationOFF() {
    var pushNotification = window.plugins.pushNotification;
    pushNotification.unregister(pushNotificationOffSuccess,
        pushNotificationOffError);
}

function pushNotificationOffSuccess() {
    alert("Noticications are OFF");
}

function pushNotificationOffError() {
    alert("Error turning noticications off");
}

在iOS7和Android 4.x上,互联网关闭(单元格和wifi)正在调用成功函数,我原本预计错误回调会被触发吗?

我在这里缺少什么,以及如何确保您不会向在设备离线时关闭它们的人发送通知?

编辑2月4日的测试结果

ANDROID Tablet
14:12:23 wifi off
14:14:23 turned notifications off
14:18:59 wifi on
14:36:08 sent push, received


IOS tablet
15.25 wifi off
15.35 turned notifications off
15.42 wifi on
16:00 sent push, NOT received




All devices
=================================

16.30 all have wi fi on, notifications on,  and receive push
16.34 turned off wifi on all
16.45 turned off notifications on all
16.55 turned ON wifi on all
17.40 sent push
17.47 not received on any device, sending another push
17.56 not received on any device


All devices 3rd feb
=================================
11.50 all have wi fi on, notifications on,  and receive push
11.55 turned OFF wifi on all
12.05 turned off notifications on all and CLOSED APP
12.45 turned ON wifi on all
13.00 sent push - received by 3 x android - but not by ios and appears in ios feedback

---------------------------------

13.40 all have wi fi on, notifications on,  and receive push
13.41 unplugged wifi
13.46 turned off notifications on all and CLOSED APP
14.07 turned on wifi
15.00 sent push - received by 2 x android - but not by ios and appears in ios feedback

---------------------------------


15.59 all have wi fi on, notifications on,  and receive push
16.00 unplugged wifi
16.02 turned off notifications on all and backgrounded app
16.43 turned on wifi
17.41 sent push - no push received on any device and one android NotRegistered returned

SUMMARY OF TODAY

seems IOS does turn off notifications (when back online again) if toggle was changed while offline
android seems to do it also, provided 
a) there is time (ie 30 min between going online again, and sending push)
b) you background app instead of closing it, after changing the toggle

1 个答案:

答案 0 :(得分:2)

Android documentation所述,取消注册不会立即发生。相反,注销可能需要5分钟才能传播。在这5分钟内发生的事情是

  

在此期间,由于未注册的状态,邮件可能会被拒绝,并且在此之后,邮件可能仍会传递给错误的用户。

因此,您已成功接收取消注册的意愿,并且该过程已启动,因此成功回调。

以下是来自 PushPlugin.java 的取消注册调用的代码,它负责响应JS

GCMRegistrar.unregister(getApplicationContext());
Log.v(TAG, "UNREGISTER");
result = true;
callbackContext.success();

正如您所看到的,唯一可能实际失败的情况是 GCMRegistrar.unregister ,它甚至不等待GCM服务器响应“好,未注册”因此导致总是返回成功。