Cordova:如何检测设备上是否禁用推送通知?

时间:2014-09-15 09:28:32

标签: cordova notifications push

我需要一种方法来确定用户是否已在其设备上禁用了我的应用的推送通知。到目前为止,我已经尝试了这个

pushNotification.register(apnSuccessfulRegistration,
  apnFailedRegistration, { 
    "badge": "true",
    "sound": "true",
    "alert": "true",
    "ecb": "pushCallbacks.onNotification"
});

在设备上启用通知时会触发apnSuccessfulRegistration

当设备上的通知被禁用时,apnSuccessfulRegistrationapnFailedRegistration不会被触发。

任何人都可以给我一个提示吗?

P.S:我正在使用Cordova版本:3.5.0

1 个答案:

答案 0 :(得分:2)

假设您使用的是官方推送通知插件com.phonegap.plugins.PushPlugin,他们已经暂时解决了这个问题:

https://github.com/phonegap-build/PushPlugin/issues/162

所以,即使使用最新版本(2.4.0。),问题仍然存在。在那个线程中,他们提出了一个解决方法,请注意它并不好,如果你没有从插件中获得响应,这基本上是一个设置全局变量的超时。

pushNotification.register(tokenHandler, errorHandler, {
    "badge":"false",
    "sound":"true",
    "alert":"true",
    "ecb":"onNotificationAPN"
});
// We assume that if the register callback hasn't happened
// within 2 seconds, there must have been some error.
setTimeout(errorHandler, 2000);

我从上面的链接中复制了它。

相关问题