phonegap推送通知显示为警报而不是推送android

时间:2014-03-16 19:21:23

标签: cordova push-notification pushwoosh

我正在使用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;
    }
}

感谢。

0 个答案:

没有答案