Start a new topic

Push Notification : ecb function executes for first time only.

I am new to Phone gap and AngularJS. I am developing an android app that integrates push notifications using Phone gap and AngularJS. The call back function only executes for the first. As i close the application and start again. I got notifications on notification bar but clicking on this does not trigger my ecb function.



My code is as follows:



.factory('GCM', ["$window", "$rootScope", function ($window, $rootScope){



function registerGCM(){

var pushNotification;

pushNotification = window.plugins.pushNotification;

pushNotification.register(

successHandler,

errorHandler, {

"senderID":"676655225205",

"ecb":"onNotificationGCM"

});



}



function successHandler(result){

//alert('result = ' + result);

}



function errorHandler(error){

alert(error);

}



$window.onNotificationGCM = function (e){

switch(e.event){

case 'registered':

if ( e.regid.length > 0 )

{

$rootScope.$broadcast('reg_key', e.regid);

}

break;



case 'message':

/*alert(e.payload.message);

if(e.payload.msg_type === "chat"){

db = window.openDatabase("OfficeMateDirectoryDB", "1.0", "OfficeMate", 200000);

db.transaction(function(tx){

tx.executeSql("UPDATE employee SET chat = chat + 1 WHERE id = '"+e.payload.emp_id+"'");

});

}*/

if (e.foreground){

//This is not executing on clicking notification on notification bar.

alert('foreground notification');

}else{

// otherwise we were launched because the user touched a notification in the notification tray.

if (e.coldstart){

alert('coldstart notification');

}else{

alert('backgroud notification');

}

}

break;



case 'error':

alert('GCM error = '+e.msg);

break;



default:

alert('An unknown GCM event has occurred');

break;

}

}



return{

register: function(){

return registerGCM();

}

};

}]);

Are you using Kinvey in any way? This seems to be a problem specific to PhoneGap + AngularJS. I’d recommend asking for support on AngularJS on the [PushPlugin GitHub repo](https://github.com/phonegap-build/PushPlugin).
Hi, Mark,

Thanx for suggestion..
Login or Signup to post a comment