Mob*_*ent 8 cordova phonegap-pushplugin
我正在使用Cordova Push Notifications Plugin 1.3.4和我的Cordova/Phonegap应用程序.不幸的是,当收到推送通知时,我的JavaScript中的ecb回调永远不会被触发,我无法处理推送通知(即使应用程序在前台运行也是如此).
我正在使用演示中的示例代码:
pushNotification.register(tokenHandler, errorHandler, {"badge": "true", "sound": "true", "alert": "true", "ecb": "onNotificationAPN"});
Run Code Online (Sandbox Code Playgroud)
注册成功,但永远不会触发以下回调:
function onNotificationAPN (event) {
if (event.alert)
{
navigator.notification.alert(event.alert);
}
}
Run Code Online (Sandbox Code Playgroud)
问题是你定义回调函数的方式,导致Push Plugin对你的回调(即,via [webView stringByEvaluatingJavaScriptFromString)的评估失败,因为它不会意识到它.
如果您将回调函数定义为全局对象,则每次新通知到达时插件都会正确触发回调:
onNotificationAPN = function(event) {
if (event.alert)
{
navigator.notification.alert(event.alert);
};
};
Run Code Online (Sandbox Code Playgroud)
对于Android,您可以onNotificationGCM用同样的方式定义回调.
| 归档时间: |
|
| 查看次数: |
6515 次 |
| 最近记录: |