gpt4 book ai didi

android - GCM 推送通知注册调用返回正常但设备未注册

转载 作者:行者123 更新时间:2023-11-30 02:41:24 24 4
gpt4 key购买 nike

使用 Phonegap Build 为 Android 设备使用推送通知请求,在注册请求时查看发生了什么!

    var pushNotification=window.plugins.pushNotification;

var return = pushNotification.register(successHandler , errorHandler,{"senderID":GCMProject,"ecb":"onNotification"});


function successHandler (result) {
alert('result = ' + result); // returned 'result = ok' //
}

function errorHandler (error) {
alert('error = ' + error);
}


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 notification happened while we were in the foreground.
// you might want to play a sound to get the user's attention, throw up a dialog, etc.
if ( e.foreground )
{
$("#app-status-ul").append('<li>--INLINE NOTIFICATION--' + '</li>');

// on Android soundname is outside the payload.
// On Amazon FireOS all custom attributes are contained within payload
var soundfile = e.soundname || e.payload.sound;
// if the notification contains a soundname, play it.
var my_media = new Media("/android_asset/www/"+ soundfile);
my_media.play();
}
else
{ // otherwise we were launched because the user touched a notification in the notification tray.
if ( e.coldstart )
{
$("#app-status-ul").append('<li>--COLDSTART NOTIFICATION--' + '</li>');
}
else
{
$("#app-status-ul").append('<li>--BACKGROUND NOTIFICATION--' + '</li>');
}
}

$("#app-status-ul").append('<li>MESSAGE -> MSG: ' + e.payload.message + '</li>');
//Only works for GCM
$("#app-status-ul").append('<li>MESSAGE -> MSGCNT: ' + e.payload.msgcnt + '</li>');

break;

case 'error':
$("#app-status-ul").append('<li>ERROR -> MSG:' + e.msg + '</li>');
break;

default:
alert('EVENT -> Unknown, an event was received and we do not know what it is');
break;
}
}

successHandler() 被触发并显示('ok')消息结果!

为什么 onNotification() 方法没有被触发???

该应用程序尚未部署到 Play 商店。它在本地使用但连接到互联网。

感谢您的建议。

最佳答案

问题出在 JS 库上,当我们将代码直接放入 index.js 时,它可以正常工作。所以这个问题包含在 PushNotification.js 脚本中定义的对象中。

关于android - GCM 推送通知注册调用返回正常但设备未注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25708437/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com