astalor
astalor

Reputation: 290

Cordova: How to detect if push notifications are disabled on the device?

I need a way to find out if the user has disabled the push notifications for my app on his device or not. So far I have tried this

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

The apnSuccessfulRegistration is triggered when the Notifications are ENABLED on the device.

The apnSuccessfulRegistration AND apnFailedRegistration are not triggered when the notifications are DISABLED on the device.

Anyone can give me a hint ?

P.S: I'm using Cordova version: 3.5.0

Upvotes: 4

Views: 3287

Answers (1)

josepo
josepo

Reputation: 66

Assuming you are using the official push notification plugin com.phonegap.plugins.PushPlugin , they've had an issue open for that for a while now:

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

so, even with the latest version (2.4.0.) the problem persists. In that very thread they propose a workaround, mind it is not nice, which is basically a timeout that sets a global variable if you do not get a response from the plugin.

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);

I copied that from the link above.

Upvotes: 2

Related Questions