我使用pushwoosh将推送通知发送到我的应用程序,我想添加一些功能来检查用户是否关闭" Revicieve Notification"在他们的设备上,我从pushwoosh发送的推送通知不会触发或警告这些设备。
PS。我用cordova。
谢谢。
答案 0 :(得分:2)
我刚刚完成了这一分钟,解决了这个问题:
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);
}
);
我们使用localstorage来保存设置,所以在我们的例子中:
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);
}
);
}
正如您可能想到的那样,这可以通过“ PushwooshAndroid.js ”进行。我还没有在iOS上做过这个,但期望它是一样的。
希望这对你有所帮助! FG
答案 1 :(得分:0)
对于Cordova,请看一下:
Pushwoosh插件中的 iOS : getRemoteNotificationStatus 功能。
检查“启用”键。
Android :您可以考虑用户注册,除非您调用“unregisterDevice”功能。由于Android没有API来检查推送注册状态。您可以在此处投票赞成此功能:https://code.google.com/p/android/issues/detail?id=38482