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'});
}
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.
,