【发布时间】:2015-05-26 02:15:11
【问题描述】:
尝试使用PushPlugin 处理推送通知。 以下是我的代码。
onNotificationGCM: function(e) {
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 )
{
console.log("Regid " + e.regid);
//alert('registration id = '+e.regid);
sDeviceId = e.regid;
//alert(sDeviceId);
}
break;
case 'message':
// this is the actual push notification. its format depends on the data model from the push server
alert('message = '+e.message);
alert('message = '+e.message+' msgcnt = '+e.msgcnt);
if ( e.foreground )
{
alert("Notification Received");
}
else
{ // otherwise we were launched because the user touched a notification in the notification tray.
if ( e.coldstart )
{
alert("coldstart");
}
else
{
alert("other than coldstart");
}
}
break;
case 'error':
alert('GCM error = '+e.msg);
break;
default:
alert('An unknown GCM event has occurred');
break;
}
}
所以一切正常。
当应用程序在前台时,我会收到警报。
当收到消息时点击通知应用 打开,我收到警报。(冷启动)
当应用程序在后台然后点击 通知应用程序进入前台,我得到了 提醒。
但是当我将应用程序保持在后台并且当我将应用程序带到前面时没有点击通知而推送通知到达时,我没有收到任何警报。那么如何处理这种情况呢?
【问题讨论】:
-
感谢 Ajoy,我已尽力解释问题。不过我会注意您的建议。
标签: cordova push-notification phonegap-plugins phonegap-pushplugin