cordova - CordovaPush plugin always returning OK on register -
i'm following docs:
http://ngcordova.com/docs/plugins/pushnotifications/
i trying follow android example, , when try register, no matter senderid is, getting ok result.
when instert actual gcm sender id, still ok instead of registration id. did setup, googled , tried solutions, still couldn't make work.
i need working, can't find issue.
use following push notification in android , ios. work you. after install app, user need open app call ecb methods. in ios, pushnotifcation's register success method returns mobile register id in result in android, return ok. in android, onnotificationgcm method called 2 type event 1) registerid , 2) notification message. have added shownotificationapn/gcm method show notification popups $ionicpopup.alert().
.run(function ($ionicplatform, pushprocessingservice) { $ionicplatform.ready(function () { try { pushprocessingservice.initialize(); } catch (e) { //hide event } }) }) .factory('pushprocessingservice', ["$window", "$ionicpopup", function ($window, $ionicpopup) { function ondeviceready() { var pushnotification = window.plugins.pushnotification; if (ionic.platform.isandroid()) { pushnotification.register(gcmsuccesshandler, gcmerrorhandler, {'senderid': 'xxxxxxxxxxxxxx', 'ecb': 'onnotificationgcm'}); } else if (ionic.platform.isios()) { var config = { "badge": "true", "sound": "true", "alert": "true", "ecb": "pushcallbacks.onnotificationapn" }; pushnotification.register(gcmsuccesshandler, gcmerrorhandler, config); } var addcallback = function addcallback(key, callback){ if(window.pushcallbacks == undefined){ window.pushcallbacks = {}; } window.pushcallbacks[key] = callback({registered:true}); } } function gcmsuccesshandler(result) { console.log("register push notification : " + result); if (ionic.platform.isios()) { var mobiletype = "ios"; var mobileregisterid = result; // save ios mobile register id in server database // call following method on callback of save addcallback("onnotificationapn", onnotificationapn); } } function gcmerrorhandler(error) { console.log("error while register push notification : " + error); } return { initialize: function () { document.addeventlistener('deviceready', ondeviceready, false); }, registerid: function (id) { var mobiletype = "android"; // save android mobile register id in server database console.log("registerid saved successfully."); }, shownotificationgcm: function (event) { $ionicpopup.alert({ title: "pajhwok notification", subtitle: event.payload.type, template: event.payload.message }); }, shownotificationapn: function (event) { $ionicpopup.alert({ title: event.messagefrom + "..", subtitle: event.alert, template: event.body }); } } }]) onnotificationapn = function(event) { if (!event.registered) { var elem = angular.element(document.queryselector('[ng-app]')); var injector = elem.injector(); var myservice = injector.get('pushprocessingservice'); myservice.shownotificationapn(event); } else { console.log("registered notification.."); } } function onnotificationgcm(e) { switch( e.event ) { case 'registered': if ( e.regid.length > 0 ) { // gcm push server needs know regid before can push device // here might want send regid later use. var elem = angular.element(document.queryselector('[ng-app]')); var injector = elem.injector(); var myservice = injector.get('pushprocessingservice'); myservice.registerid(e.regid); } break; case 'message': // if flag set, notification happened while in foreground. // might want play sound user's attention, throw dialog, etc. var elem = angular.element(document.queryselector('[ng-app]')); var injector = elem.injector(); var myservice = injector.get('pushprocessingservice'); myservice.shownotificationgcm(e); break; case 'error': alert('<li>error :' + e.msg + '</li>'); break; default: alert('<li>unknown, event received , not know is.</li>'); break; } }
Comments
Post a Comment