thomaslindstrom/cordova-plugin-push-notifications-status

undefined PushNotificationsStatus.getStatus

Closed this issue · 5 comments

maito commented

In Cordova version 6.5.0

const PushNotificationsStatus = window.cordova.plugins;
PushNotificationsStatus.getStatus(function (status) {
if (status === 'authorized') {
console.log('Push notifications are enabled');
}
});

In result,
There is TypeError: undefined is not an object (evaluating 'PushNotificationsStatus.getStatus').

What about do I make mistake ?

Please teach me.

Hi! It’s important you destructure the object.

const {PushNotificationsStatus} = window.cordova.plugins;

PushNotificationsStatus.getStatus(function (status) {
    if (status === 'authorized') {
        console.log('Push notifications are enabled');
    }
});

If you can’t use destructuring, try this:

var PushNotificationsStatus = window.cordova.plugins.PushNotificationsStatus;

PushNotificationsStatus.getStatus(function (status) {
    if (status === 'authorized') {
        console.log('Push notifications are enabled');
    }
});
maito commented

Thank you for code.

I tried this code.

Sorry.

There is the error
TypeError: undefined is not an object (evaluating 'window.cordova.plugins.PushNotificationsStatus')

document.addEventListener('deviceready', function(){
var PushNotificationsStatus = window.cordova.plugins.PushNotificationsStatus;
PushNotificationsStatus.getStatus(function (status) {
if (status === 'authorized') {
console.log('Push notifications are enabled');
}
});

Have you installed the plugin?
cordova plugin add cordova-plugin-push-notifications-status
https://cordova.apache.org/docs/en/3.0.0/guide/cli/index.html#add-features

maito commented

sorry!

I mistake.

There is no problem.

Thank you a lot.

Please close this issue.

Alright, thanks! Let me know if there’s anything else.