【发布时间】:2015-12-18 05:44:38
【问题描述】:
我正在使用cordova 的推送插件。当用户点击通知时,它会按预期将他们带到“广告页面”。但奇怪的是,它只有在我在 onResume() 中包含 alert() 或者在点击通知后再次打开应用程序时才有效。
function onNotificationAPN(e) {
// Event callback that gets called when your device receives a
// notification
imgURL = e.imgURL; //should get set at same time notification appears
if (e.alert) {
navigator.notification.alert(e.alert);
}
}
function onResume() {
alert(imgURL); //1st
if(imgURL)
{
alert(imgURL); //2nd
window.location.href = "ad.html";
imgURL = null;
}
}
第一个警报显示“未定义”。但是第二个警报显示了我的通知有效负载中设置的 imageURL。如果我将第一个警报注释掉,则不会出现第二个警报。但是,如果我关闭并重新打开该应用程序,它会这样做。
这是怎么回事?
【问题讨论】:
-
onResume在onNotificationAPN之前被调用。你为什么不在onNotificationAPN做重定向? -
@jcesarmobile 不是先调用 onNotificationAPN() 吗?它使应用程序在后台运行时出现通知,所以我认为它也会在这个时候设置 imgURL。
-
在两者上都写一个日志,看看之前调用了哪个,但如果 imgURL 为 null 除非你使用超时,
onResume它可能在之前被调用
标签: javascript ios cordova push-notification push