Denis Matafonov Denis Matafonov - 1 month ago 9
iOS Question

GCM registrationId is not received on phonegap push plugin

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


});

Answer

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: data.registrationId},
            success: function (json) {
                alert('Phone registered' + data.registrationId);
            }
        });
    }

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

Comments