简体   繁体   English

GCM推送通知注册呼叫返回确定,但设备未注册

[英]GCM Push Notification registration call returns ok but device is not registered

Using Phonegap Build to use a push notifications requests for Android devices, when doing registration the request and see what's happened! 使用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;
  }
}

The successHandler() is fired with ('ok') message result! 使用('ok')消息结果触发successHandler()

Why the onNotification() method is not fired any time??? 为什么the onNotification()任何时候都不会触发the onNotification()方法???

The application is not deployed on Play Store yet. 该应用程序尚未部署在Play商店上。 It is used locally but connected to the internet. 它在本地使用,但已连接到Internet。

Thank you for your suggestions. 谢谢你的建议。

The problem was with the JS Library, when we put the code directly into index.js, it works properly. 问题在于JS库,当我们将代码直接放入index.js时,它可以正常工作。 So the problem wa included into the object define in the PushNotification.js script. 因此,问题已包含在PushNotification.js脚本的对象定义中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM