GCM registrationId在phonegap推送插件上未收到 [英] GCM registrationId is not received on phonegap push plugin

查看:152
本文介绍了GCM registrationId在phonegap推送插件上未收到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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



以下是插件的设置:

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

这个事件永远不会被调用:

< pre $ 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,
}
});
$ b 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));
});

函数registerDeviceToken(deviceToken){
//根据webservice类型和参数配置集注册registrationId或deviceToken到您的服务器
//从您的$ b代码片段$ b $ .ajax({
url:'/ authentication / ajax-register-gcm-token /',
data:{token:data.registrationId},
success:function(json ){
alert('Phone registered'+ data.registrationId);
}
});
}

没有SenderID 提到这里也是官方链接。确保您在项目的功能部分下启用了推送通知服务,并且您已在服务器端代码处放置了正确的开发生产 APNS p12文件及其各自的密码。因此,如果您使用开发概要文件运行App,则应该有开发p12文件环境发送推送通知,以便在您的iOS设备上接收。要设置开发和生产APNS p12证书,请参阅以下链接: APNS设置


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


    });

解决方案

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

这篇关于GCM registrationId在phonegap推送插件上未收到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆