phonegap 推送插件未收到 GCM registrationId

GCM registrationId is not received on phonegap push plugin

几天前,我有一个 在使用 phonegap 推送插件时获取 APNS 令牌而不是 GCM 令牌。

好吧,我更改了设置,我将 senderID 放在 [ios] 块中,重新编译了应用程序。现在我在 Iphone 上根本没有得到任何 regustrationId。它在 Android 上仍然可以正常工作。谁能告诉我什么是问题?

插件设置如下:

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

此事件从未被调用:

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

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


    });

您用来初始化推送通知插件对象的代码是错误的。它应该如下所示:

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);
            }
        });
    }

没有提到 SenderIDhere 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