Reputation: 3128
I using pushwoosh to send the push notification to my app and I would like to add some feature to check that if user is turn off "Revicieve Notification" on their devices, the push notification that I sent from pushwoosh will not fire or alert to those devices.
PS. I use cordova.
Thank you.
Upvotes: 1
Views: 1708
Reputation: 113
I've just gone through this minutes ago, solved with this:
pushNotification.unregisterDevice(
function (token) {
console.log("unregisterDevice, token: " + token);
//alert("unregisterDevice, token: " + token);
},
function (status) {
console.warn("registerDevice failed, status:" + status);
//alert("registerDevice failed, status:" + status);
}
);
We use localstorage to save settings, so in our case:
var storage = window.localStorage;
if (storage.getItem('pushNotification') == 'true') {
console.log('Pusnotifications ON');
//register for push notifications
pushNotification.registerDevice(
function (token) {
console.log('registerDevice, token: ' + token);
//alert('registerDevice, token: ' + token);
//callback when pushwoosh is ready
onPushwooshAndroidInitialized(token);
},
function (status) {
//alert("registerDevice failed to register, status: " + status);
console.warn(JSON.stringify(["registerDevice failed to register, status: ", status]));
}
);
} else if (storage.getItem('pushNotification') == 'false') {
console.log('Pusnotifications OFF');
//unregister for push notifications
pushNotification.unregisterDevice(
function (token) {
console.log("unregisterDevice, token: " + token);
//alert("unregisterDevice, token: " + token);
},
function (status) {
console.warn("registerDevice failed, status:" + status);
//alert("registerDevice failed, status:" + status);
}
);
}
As you might just figured out, this goes in 'PushwooshAndroid.js'. I've not done this in iOS yet, but expect it to be the same.
Hope this helps you! FG
Upvotes: 2
Reputation: 2121
For Cordova take a look on:
iOS: getRemoteNotificationStatus function in Pushwoosh plugin.
Check "enabled" key there.
Android: You may consider user registered unless you call "unregisterDevice" function. As there is no API for Android to check push registration status. You can vote up here for this feature: https://code.google.com/p/android/issues/detail?id=38482
Upvotes: 0