Cordova:干净的方式检查用户是否启用了推送通知

Joh*_*ner 1 push-notification ios cordova

看起来可能有一个现有的cordova解决方案,但除了cordovaBadge插件之外我找不到它 - https://github.com/katzer/cordova-plugin-badge - http://ngcordova.com/docs /插件/徽章/

问题是由于与LocalNotifications冲突,我不得不删除此插件.(好像我不能同时拥有它们)

cordovaBadge有一个简单的.hasPermission()方法.在cordova库中还有什么可以做到这一点吗?

Dav*_*den 5

你可以使用isRemoteNotificationsEnabled()的方法科尔多瓦诊断-插件:

cordova.plugins.diagnostic.isRemoteNotificationsEnabled(function(isEnabled){
    console.log("Push notifications are " + (isEnabled ? "enabled" : "disabled"));
}, function(error){
    console.error("An error occurred: "+error);
});
Run Code Online (Sandbox Code Playgroud)

  • 该答案发布后,该插件已经更新:现在Android和iOS都支持`isRemoteNotificationsEnabled()`. (2认同)