Reputation: 46
I'm working on an Android app with Cordova, and I have PushPlugin implemented. Everything works fine when the initial index.html file loads, but as soon as I load another html page, the onNotification function is not getting called.
From the LogCat I can see that the Javascript is being sent properly, but it is seemingly never being received. If I go on a third page, it will again work but then the fourth page won't. It's very weird because the success function is being called, but the onNotification is not.
Here is my code:
document.addEventListener("deviceready", onDeviceReady, false);
var pushNotification;
function onDeviceReady() {
pushNotification = window.plugins.pushNotification;
setupNotifications();
}
function setupNotifications() {
if ( device.platform == 'android' || device.platform == 'Android' || device.platform == "amazon-fireos" ){
pushNotification.register(
successHandler,
errorHandler,
{
"senderID":"527612045331",
"ecb":"onNotification"
});
} else {
pushNotification.register(
tokenHandler,
errorHandler,
{
"badge":"true",
"sound":"true",
"alert":"true",
"ecb":"onNotificationAPN"
});
}
}
// Android and Amazon Fire OS
function onNotification(e) {
// NOT REACHING HERE ON SECOND PAGES
switch( e.event )
{
case 'registered':
registerGCM(e.regid);
break;
case 'message':
var notificationType = e.payload.data.type;
break;
case 'error':
return;
default:
return;
}
}
Any help is appreciated.
Upvotes: 0
Views: 393
Reputation: 19
I had the same problem, I added 0.0.0.0/0 as ip address in gcm server key and it helped:
Upvotes: 0
Reputation:
onNotification must be have scope in window.
window.onNotification = function(){
}
Upvotes: 1