问题
I read every topic and tried every way. About 2 days and i still didnt get Reg ID. MY Sender ID is right and check every example in real device. Also i tried
this one
this one
this one
this one
And thoses are just some pages. I almost tried everything and still get just okey message in success handler. Can someone tell me where is my mistake ?
var xxx = angular.module('starter', ['ionic', 'ngCordova'])
xxx.run(function ($ionicPlatform, $cordovaPush) {
$ionicPlatform.ready(function () {
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if (window.StatusBar) {
StatusBar.styleDefault();
}
var androidConfig = {
"senderID": "5757xxxxxxx",
};
document.addEventListener("deviceready", function () {
$cordovaPush.register(androidConfig).then(function (result) {
alert(result);
}, function (err) {
alert(err);
})
$rootScope.$on('$cordovaPush:notificationReceived', function (event, notification) {
switch (notification.event) {
case 'registered':
if (notification.regid.length > 0) {
alert('registration ID = ' + notification.regid);
}
break;
case 'message':
// this is the actual push notification. its format depends on the data model from the push server
alert('message = ' + notification.message + ' msgCount = ' + notification.msgcnt);
break;
case 'error':
alert('GCM error = ' + notification.msg);
break;
default:
alert('An unknown GCM event has occurred');
break;
}
});
// WARNING: dangerous to unregister (results in loss of tokenID)
$cordovaPush.unregister(options).then(function (result) {
// Success!
}, function (err) {
// Error
})
}, false)
});
});
来源:https://stackoverflow.com/questions/31811170/ionic-cant-get-reg-id-for-gcm