1

我正在使用 Phonegap 推送插件 + pushwoosh 插件我有一个问题:当应用程序关闭时,我没有收到任何推送通知,当应用程序打开时,我收到它作为警报。

我想在这两种情况下都收到推送通知。

我的 onDeviceReady 函数是:

function onDeviceReady()
{
    var pushNotification;
    try
    {
        pushNotification = window.plugins.pushNotification;
        if (isAndroid())
        {
            pushNotification.register(successHandler, errorHandler, {"senderID":"179400841357","ecb":"onNotificationGCM"});     // required!
        }
        else
        {
            pushNotification.register(tokenHandler, errorHandler, {"badge":"true","sound":"true","alert":"true","ecb":"onNotificationAPN"});    // required!
        }
    }
    catch(err)
    {
        txt="There was an error on this page.\n\n";
        txt+="Error description: " + err.message + "\n\n";
        alert(txt);
    }
}

onNotificationGCM 函数:

function onNotificationGCM(e)
{
    switch( e.event )
    {
        case 'registered':
            if ( e.regid.length > 0 )
            {
                //alert("entering to pushwoosh");
                // 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.
                PushWoosh.appCode = "94550-3136B";
                PushWoosh.register(e.regid, function(data)
                {
                    console.log("PushWoosh register success: " + JSON.stringify(data));
                    //alert("succeded");
                }, function(errorregistration) {
                    console.log("Couldn't register with PushWoosh" +  errorregistration);
                    //alert("oh shit!");
                });

            }
            break;

        case 'message':
            navigator.notification.alert(e.payload);
            // 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)
            {
                // if the notification contains a soundname, play it.
                var my_media = new Media("/android_asset/www/"+e.soundname);
                my_media.play();
            }

            break;

        default:
            break;
    }
}

谢谢。

4

0 回答 0