我阅读了每个主题,并尝试各方面。大约2天,我仍然没有获得Reg ID。我的发件人ID是正确的,并检查真实设备中的每个示例。我也试过
而且只是一些页面。我几乎尝试了一切,仍然只是成功处理程序中的okey消息。有人能告诉我我的错误在哪里吗?
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)
});
});