android - Can't get device token using Cordova Push Notifications Plugin -
i'm building push notification app using ionic framework, try following sample app: https://github.com/hollyschinsky/pushnotificationsample
the problem when try run sample in android device doesn't retrive device token. replaced senderid in register function 1 own google application, doesn't work.
what doing wrong?
here versions i'm using:
ionic --version 1.3.20 cordova --version 5.0.0 phonegap --version 4.2.0-0.24.2 android device: htc 1 s android version: 4.1.1 htc sense 4+
the problem think in here in notificationreceived function:
// register $scope.register = function () { var config = null; if (ionic.platform.isandroid()) { config = { "senderid": "1034029444859" // replace yours gcm console - in project url like: https://console.developers.google.com/project/434205989073 }; //alert("el senderid es: " + senderid); } else if (ionic.platform.isios()) { config = { "badge": "true", "sound": "true", "alert": "true" } } $cordovapush.register(config).then(function (result) { console.log("register success " + result); $cordovatoast.showshortcenter('registered push notifications ' + config.senderid); $scope.registerdisabled=true; // ** note: android regid result comes in pushnotificationreceived, ios returned here if (ionic.platform.isios()) { $scope.regid = result; storedevicetoken("ios"); } }, function (err) { console.log("register error " + err) }); } // notification received $scope.$on('$cordovapush:notificationreceived', function (event, notification) { console.log(json.stringify([notification])); if (ionic.platform.isandroid()) { handleandroid(notification); } else if (ionic.platform.isios()) { handleios(notification); $scope.$apply(function () { $scope.notifications.push(json.stringify(notification.alert)); }) } });
edit:
it turns out app retrieves device token, not displaing on screen should.
i had run app on device connected via usb , ionic run android, , see how app running adb logcat, saw line said "registrationid = apa91b..." that's token. tested notifications sendgcm.js file indicated in tutorial , works.
but still doesn't explains why doesn't show token or received notifications in index page. token out of controllers scope.
any help?
it's because didn't set push notifications properly.
what need remove existing certificates in member developer account , rebuild again. if try debug takes time.
you can check here if want see step step how create push notification using cordova push plugin.
sorry not posting here steps because it's long. feel free ask.
Comments
Post a Comment