仅获取字符串“;“好的”;而不是使用Android的cordova push插件的设备/注册id
我已经设置了推送通知插件并调用了register方法,但是它只返回一个字符串“OK”,而不是一个设备id。我如何获得注册的设备id仅获取字符串“;“好的”;而不是使用Android的cordova push插件的设备/注册id,cordova,cordova-plugins,phonegap-pushplugin,Cordova,Cordova Plugins,Phonegap Pushplugin,我已经设置了推送通知插件并调用了register方法,但是它只返回一个字符串“OK”,而不是一个设备id。我如何获得注册的设备id $window.plugins.pushNotification.register( function (result) { q.resolve(result); //this always just returns the string "OK", how do I get the device ID?
$window.plugins.pushNotification.register(
function (result) {
q.resolve(result); //this always just returns the string "OK", how do I get the device ID?
},
function (error) {
console.log(error);
q.reject(error);
},
config);
return q.promise;
},
e、 regid为null,取自本例
// Android and Amazon Fire OS
function onNotification(e) {
$("#app-status-ul").append('<li>EVENT -> RECEIVED:' + e.event + '</li>');
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 )
{
$("#app-status-ul").append('<li>REGISTERED -> REGID:' + e.regid + "</li>");
// Your GCM push server needs to know the regID before it can push to this device
// here is where you might want to send it the regID for later use.
console.log("regID = " + e.regid);
}
break;
case 'message':
// if this flag is set, this noti
//Android和Amazon Fire操作系统
通知功能(e){
$(“#应用程序状态ul”).append(“事件->接收:“+e.EVENT+” ”);
开关(如事件)
{
“已登记”案件:
如果(e.regid.length>0)
{
$(“#应用程序状态ul”)。附加(“已注册->REGID:”+e.REGID+“ ”);
//您的GCM推送服务器需要知道regID才能推送到此设备
//这里是您可能希望发送regID供以后使用的地方。
console.log(“regID=“+e.regID”);
}
打破
案例“信息”:
//如果设置了此标志,则此noti
所以我只是误解了推送库中的回调。iOS上的注册函数回调返回一个字符串令牌,而在Android中它只返回一个成功处理程序。Android版本中注册事件的令牌id必须在推送通知ecb处理程序中处理,而不是在注册回调中处理
所以在他们的例子中
if ( device.platform == 'android' || device.platform == 'Android' || device.platform == "amazon-fireos" ){
pushNotification.register(
successHandler,
errorHandler,
{
"senderID":"replace_with_sender_id",
"ecb":"onNotification"
});
}
该函数在配置属性“ecb”中设置为“onNotification”,而不是在sucess处理程序中
在这种情况下,您可以在原始问题中使用onNotification示例。我的错误是将onNotification函数作为Android中的成功处理程序传递,但事实并非如此。关于注册,我的错误是使用了错误的项目id。起初我使用的是唯一的名称(在开发控制台中也称为项目id),而不是项目编号。无论gcm的响应如何,回调都是成功的 在我的两台三星测试设备上,我也遇到了类似的问题:寄存器回调工作正常,但应用程序没有收到推送通知。这似乎与我的测试设备上的某些服务过时有关
最后,如果希望通知正确显示在系统托盘中,请确保在有效负载数据中包含“消息”和“标题”。在android中,当触发设备注册事件时,可以从ecb回调中获取设备令牌。此代码说明了我是如何做到这一点的(它可以更有组织性,但就我们的目的而言,它是足够的): 然后使用其功能:
registerWithGCMServer()
.then(function(deviceToken) {
console.log('Device registered and its token is ' + deviceToken);
})
.fail(function(e) {
console.error(e);
});
function onMessageRecived(message) {
console.log('Push message received: ' + message);
}
关于这个问题,我在其他线程中读到,Android
successHandler
回调返回“OK”
表示您已成功与GCM服务器进行通信,但实际上尚未使用GCM API正确识别您的客户机。请参阅。您能否提供一个如何“处理推送通知ecb处理程序”的示例?在回答中添加了示例-另请参阅上述问题中有关ecb处理程序的参考。非常好的教程Al是一个可用的[here][1]示例。[1]:节省了我很多时间,伙计。欠你一个:)
registerWithGCMServer()
.then(function(deviceToken) {
console.log('Device registered and its token is ' + deviceToken);
})
.fail(function(e) {
console.error(e);
});
function onMessageRecived(message) {
console.log('Push message received: ' + message);
}