Cordoba PushPlugin registers receipt of ERROR

I use PubNub for push notifications on mobile devices. For my project, I used the following code. In accordance with the direction of the following link.

https://www.pubnub.com/blog/2014-12-18-sending-android-push-notifications-via-gcm-javascript-using-phonegap/

var pushNotification = window.plugins.pushNotification;

    pushNotification.register(
        successHandler, 
        errorHandler, 
        {
            'senderID':'projectID'
        }
    );

    function successHandler(result) {
        alert('Success: '+ result);
    }
    function errorHandler(error) {
        alert('Error: '+ error);
    }

But this call notification register calls the function errorHandler. And it shows the error message "Class not found."

Why am I getting this error?

Any please suggest

New update

According to the link above, I added the following code to my cordova project.

function initialize() {
    bindEvents();
}
function bindEvents() {
    document.addEventListener('deviceready', init, false);
}

function init() {
    var pushNotification = window.plugins.pushNotification;
    pushNotification.register(successHandler, errorHandler, {'senderID':'projectID','ecb':'onNotificationGCM'});
    // Get your Sender ID at cloud.google.com/console
}

function successHandler(result) {
    alert('Success: '+ result);
}

function errorHandler(error) {
    alert('Error: '+ error);
}

function onNotificationGCM(e) {
    switch( e.event ){
        case 'registered':
            if ( e.regid.length > 0 ){
                console.log('regid = '+e.regid);
                alert(e.regid);
            }
        break;

        case 'message':
            console.log(e);
            if (e.foreground){
                alert('The room temperature is set too high')
            }
        break;

        case 'error':
            alert('Error: '+e.msg);
        break;

        default:
          console.log('An unknown event was received');
          break;
    }
}

initialize();

. successHandler "OK". onNotificationGCM, .

cordova.

,

+4
1

ecb, :

pushNotification.register(
  successHandler, 
  errorHandler, 
  {
    'senderID':'your_sender_id',
    'ecb':'onNotificationGCM' // callback function
  }
);

:

function onNotificationGCM(e) {
  case 'registered':
    if (e.regid.length > 0){
      deviceRegistered(e.regid);
    }
  break;
  case 'message':
    if (e.foreground){
      // When the app is running foreground. 
    }
  break;
  case 'error':
    console.log('Error: ' + e.msg);
  break;
  default:
    console.log('An unknown event was received');
  break;
}

, readme.md GitHub repo. , "".

0

Source: https://habr.com/ru/post/1618067/


All Articles