cordova - PushPlugin does not register device and return regid on onNotificationGCM -
i have install pushplugin phonegap 3.4.
the onnotificationgcm case:registered has never execute, unable store regid in server database , starts send notification.
whenever app opens, shows
- deviceready event received
- registering android
- success ok
i have done:
- changed senderid
- google cloud messaging android - on
- created server key (but should not important not @ sending portion)
do need:
- to install google play service api?
- what missing ?
i waited few minutes there no registered message like
$("#app-status-ul").append('<li>registered -> regid:' + e.regid + "</li>");
i had problem you. remove line of codes contain html thing. if want retrieve it, store sessionstorage/localstorage, console or alert it.
my html remove version
var pushnotification; document.addeventlistener("deviceready", ondeviceready, false); // device apis available // function ondeviceready() { pushnotification = window.plugins.pushnotification; if (device.platform == 'android' || device.platform == 'android') { console.log("registering android"); window.plugins.pushnotification.register(successhandler, errorhandler, { "senderid": "xxxxxxxxxxx", "ecb": "onnotificationgcm" }); // required! } else { console.log("registering ios"); pushnotification.register(tokenhandler, errorhandler, { "badge": "true", "sound": "true", "alert": "true", "ecb": "onnotificationapn" }); // required! } } // handle apns notifications ios function onnotificationapn(e) { if (e.alert) { navigator.notification.alert(e.alert); } if (e.sound) { var snd = new media(e.sound); snd.play(); } if (e.badge) { pushnotification.setapplicationiconbadgenumber(successhandler, e.badge); } } // handle gcm notifications android function onnotificationgcm(e) { navigator.notification.alert(e.event); switch (e.event) { case 'registered': if (e.regid.length > 0) { navigator.notification.alert(e.regid); // gcm push server needs know regid before can push device // here might want send regid later use. console.log("regid = " + e.regid); sessionstorage.setitem("deviceid",e.regid); } break; case 'message': // if flag set, notification happened while in foreground. // might want play sound user's attention, throw dialog, etc. if (e.foreground) { navigator.notification.alert('--inline notification--'); // if notification contains soundname, play it. var my_media = new media("/android_asset/www/" + e.soundname); my_media.play(); } else { // otherwise launched because user touched notification in notification tray. if (e.coldstart) navigator.notification.alert('--coldstart notification--'); else navigator.notification.alert('--background notification--'); } navigator.notification.alert(e.payload.message); navigator.notification.alert('message -> msgcnt: ' + e.payload.msgcnt); break; case 'error': navigator.notification.alert('error -> msg:' + e.msg); break; default: navigator.notification.alert('event -> unknown, event received , not know is'); break; } } function tokenhandler(result) { navigator.notification.alert(result, null, 'alert', 'ok'); sessionstorage.setitem("deviceid", result); sessionstorage.setitem("notificationserver", "apns"); // ios push server needs know token before can push device // here might want send token later use. } function successhandler(result) { navigator.notification.alert(result, null, 'alert', 'ok'); sessionstorage.setitem("deviceid", result); sessionstorage.setitem("notificationserver", "gcm"); } function errorhandler(error) { navigator.notification.alert(error, null, 'alert', 'ok'); }
Comments
Post a Comment