Ionic cant get Reg ID for GCM

末鹿安然 提交于 2020-01-17 13:42:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!