参考错误onnotification没有在推送通知cordova android中定义
Reference error onnotification is not defined in push notification cordova android
使用Cordova(ionicframework+angularjs)Build为Android设备使用推送通知请求。注册时successHandler()
被触发,消息结果为('ok')!为什么onNotification()
方法在任何时候都没有被激发??。
var pushNotification;
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
pushNotification = window.plugins.pushNotification;
setupNotificationsForandroid();
}
//begin setup
function setupNotificationsForandroid() {
// alert("inside setup");
if ( device.platform == 'android' || device.platform == 'Android' || device.platform == "amazon-fireos" ){
pushNotification.register(
successHandler,
errorHandler,
{
"senderID":"856763042820",
"ecb":"onNotification"
});
} else {
pushNotification.register(
tokenHandler,
errorHandler,
{
"badge":"true",
"sound":"true",
"alert":"true",
"ecb":"onNotificationAPN"
});
}
}
function successHandler(result){
//alert("success"+result);
}
function errorHandler(){
alert("error");
}
// Android
function onNotification(e) {
//alert("inside onnotification");
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 ){
//set up the server call for storing registraion ids
alert(e.regid);
}
break;
case 'message':
// if this flag is set, this notification happened while we were in the foreground.
if(e.foreground){
var soundfile = e.soundname || e.payload.sound;
var my_media = new Media("android/assets/www/"+ soundfile);
my_media.play();
}else{
// otherwise we were launched because the user touched a notification in the notification tray.
}
break;
case 'error':
console.log("Error"+e.msg);
break;
default:
console.log("An unknown event");
return;
}
}
这是我的控制台消息:
09-22 11:38:46.151: I/Web Console(24662): processMessage failed: Stack: ReferenceError: onNotification is not defined
09-22 11:38:46.151: I/Web Console(24662): at eval (eval at processMessage (file:///android_asset/www/cordova.js:1006:26), <anonymous>:1:1)
09-22 11:38:46.151: I/Web Console(24662): at processMessage (file:///android_asset/www/cordova.js:1006:13)
09-22 11:38:46.151: I/Web Console(24662): at Function.androidExec.processMessages (file:///android_asset/www/cordova.js:1076:13)
09-22 11:38:46.151: I/Web Console(24662): at pollOnce (file:///android_asset/www/cordova.js:944:17)
09-22 11:38:46.151: I/Web Console(24662): at pollOnceFromOnlineEvent (file:///android_asset/www/cordova.js:939:5) at file:///android_asset/www/cordova.js:1045
09-22 11:38:46.151: D/CordovaLog(24662): file:///android_asset/www/cordova.js: Line 1046 : processMessage failed: Message: Jjavascript:onNotification({"regid":"APA91bHDLg9BZl-eicx3tS-MjVGy-mcufmbRc-EpCuKzb9b_tPddG125jyxY-OhVR5vul6az-eJ2nZ0PEiOVPqP2KjClaUwAKTBQx5gsIluI0jsGIrpCvNQdUbtKUBxNNH0DH94RHuGpjU29xhTS5Cl8qIgH1MlJHw","event":"registered"})
根据这个processMessage failed: Stack: ReferenceError: onNotification is not defined
控制台消息,我认为onNotification()
有问题。请帮助
onNotification必须在窗口中具有作用域。
window.onNotification = function(){
}
相关文章:
- Firebase2(Firebase.google.com)推送通知-从外部管理
- cordova-2.0.0.js不适用于使用phonegap的android
- ReferenceError: cordova is not defined @ng-cordova.min.js:7
- 无法在窗口内使用rootScope.通知
- 如何使用Quickblox在Cordova应用程序中实现推送通知支持
- Cordova:如何显示系统通知
- 触发 iOS 的本地通知 - Cordova/Phonegap
- 使用 cordova 推送插件处理解析推送通知
- Cordova/PhoneGap在没有服务器的情况下推送通知
- Cordova通过推送通知检测冷启动
- 导航器通知警报在Cordova不起作用
- 参考错误onnotification没有在推送通知cordova android中定义
- 是否有任何工作的Cordova推送通知
- 我不能使用cordova本地通知插件取消通知
- 显示推送通知只有当应用程序不运行在cordova android
- cordova 3.5.0的本地通知不工作
- 如何在cordova中通过GCM实现大图样式的推送通知
- Android本地通知Cordova:等待cancelAll完成
- 通知.警告不工作cordova版本4+
- 使用PhoneGap / Cordova的web应用的状态栏通知