GCM registrationId is not received on phonegap push plugin

半世苍凉 提交于 2020-01-07 02:22:14

问题


Couple days ago I had an issue with getting APNS token instead of GCM token while using phonegap push plugin.

Well, I changed setup, I've put senderID in [ios] block, recompiled the app. Now I dont get ANY regustrationId at all on Iphone. It still works fine on Android. Can anyone tell me what can be a problem?

Here is setup of plugin:

 var push = PushNotification.init({
        android: {
            senderID: "8225....8910"
        },
        ios: {
            senderID: "8225....8910",
            alert: "true",
            badge: "true",
            sound: "false"
        },
        windows: {}
    });

And this event is never being called:

    push.on('registration', function(data) {

        $.ajax({
            url: '/authentication/ajax-register-gcm-token/',
            data: {token: data.registrationId},
            success: function (json) {
                alert('Phone registered' + data.registrationId);
            }
        });


    });

回答1:


The code you have used to initialize Push Notification Plugin Object is wrong. It should be as below:

var push = PushNotification.init({
            android: {
                senderID: "XXXXXXXXXXXX",
            },
            ios: {
                alert: "true",
                badge: "true",
                sound: "true",
            }
        });

    push.on('registration', function(data) {
        console.log(data.registrationId);
        registerDeviceToken(data.registrationId);
        });

    push.on('notification', function(data) {
        console.log("notification event");
         alert(JSON.stringify(data));
         });

    push.on('error', function(e) {
        console.log("push error");
        alert(JSON.stringify(e));
    });

    function registerDeviceToken(deviceToken){
    //Register the registrationId or deviceToken to your server as per the webservice type and parameters configuration set
//From your code snippet above
$.ajax({
            url: '/authentication/ajax-register-gcm-token/',
            data: {token: deviceToken},
            success: function (json) {
                alert('Phone registered' + deviceToken);
            }
        });
    }

There is no SenderID mentioned here in official link as well. Make sure you have turned on Push Notification service under Capabilities section of your Project and you have put correct development and production APNS p12 files and their respective passwords at the server side code. So if you are running App with Development Profile then there should be development p12 file environment sending Push Notification in order to be received on your iOS device. To set up Development and Production APNS p12 certificate, refer this link: APNS setup



来源:https://stackoverflow.com/questions/38268507/gcm-registrationid-is-not-received-on-phonegap-push-plugin

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