Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova: clean way to check if user has enabled push notifications

Seems like there is probably an existing cordova solution for this, but I can't find it other than the cordovaBadge plugin - https://github.com/katzer/cordova-plugin-badge - http://ngcordova.com/docs/plugins/badge/

Problem is I have had to remove this plugin due to conflicts with LocalNotifications. (Seems like I can't have them both)

The cordovaBadge has a simple .hasPermission() method. Is there anything else in the cordova library that can do this?

like image 858
Kinglish Avatar asked Oct 31 '25 04:10

Kinglish


1 Answers

You could use the isRemoteNotificationsEnabled() method of cordova-diagnostic-plugin:

cordova.plugins.diagnostic.isRemoteNotificationsEnabled(function(isEnabled){
    console.log("Push notifications are " + (isEnabled ? "enabled" : "disabled"));
}, function(error){
    console.error("An error occurred: "+error);
});
like image 108
DaveAlden Avatar answered Nov 01 '25 22:11

DaveAlden