我正在为Android/IOS做pushnotification。科尔多瓦PushNotification onNotificationGCM不叫
我已经使用了一个科尔多瓦推送插件https://github.com/phonegap-build/PushPlugin,它似乎很好。
信息:我在一个AngularJS项目。
在我NotificationHelper厂我有这个init方法:
helper.init = function() {
// Instanciate push plugin notification
var pushNotification = window.plugins.pushNotification;
var errorHandler = function(error) {
logger.debug('errorHandler = ' + error);
};
if ($rootScope.isAndroid()) {
var senderId = CONFIG.NOTIFICATION_ANDROID_SENDER_ID;
pushNotification.register(function(result) {
logger.debug('successHandler = ' + result);
}, errorHandler, {
'senderID' : senderId,
'ecb' : 'onNotificationGCM'
});
}
};
我还定义上mains.js这些方法:
var onNotificationGCM = function(event) {
// call back to web service in Angular.
var elem = angular.element(document.querySelector('[ng-app]'));
var injector = elem.injector();
var service = injector.get('NotificationHelper');
service.onNotificationGCM(event);
};
这是一招,从主要的Javascript调用angularJS工厂。
'onNotificationGCM' 叫 'NotificationHelper.onNotificationGCM' 的方法:
helper.onNotificationGCM = function(e) {
switch (e.event) {
case 'message':
// Notification happened while app was in the foreground
if (e.foreground) {
logger.debug('[notification] [message] Foreground : ' + JSON.stringify(e));
} else { // Notification touched in the notification tray
logger.debug('[notification] [message] Background : ' + JSON.stringify(e));
if (e.coldstart) {
// App was not running and user clicked on notification
} else {
// App was running and user clicked on notification
}
}
decriptPayloadNotification(e.payload);
break;
case 'registered':
logger.debug('[notification] [registered] : ' + JSON.stringify(e));
if (e.regid.length > 0) {
registerUser(e.regid, 'gcm');
}
break;
case 'error':
logger.debug('[notification] [error] : ' + JSON.stringify(e));
break;
default:
logger.debug('[notification] [default] : Unknown, an event was received and we do not know what it is : ' + JSON.stringify(e));
break;
}
};
在第一次使用时,一切工作良好:收到
- '注册' 的事件接收
- 当我在前台我收到'消息'事件:
NotificationHelper:[notification] [message] Foreground:{“event”:“message”,“from”:“847593779913”,“message”:“Agenêts23/03 10h \ r \ n”,“collapse_key “:”do_not_collapse“,”foreground“:true,”有效载荷“:{”lt“:”school“,”lv“:”E1154“,”notId“:”35429“,”title“:”Agenêtsle 23/03/2015" , “消息”: “Agenêts23/03 10H \ r \ n” 个}}
- 当我在背景,如果收到通知符和TOUCHE它通知盘,收到'message'event:
通知帮助:[通知] [信息]背景:{“event”:“message”,“from”:“847593779913”,“message”:“la piscine serafermée1journéepour raison technique”,“coldstart”:false ,“collapse_key”:“do_not_collapse”,“foreground”:false,“payload”:{“lt”:“游泳池”,“lv”:“E114”,“notId”:“29869”,“title” 23/04/2015 fermeture德拉鱼”,‘消息’:‘拉鱼的血清fermée1个JOURNEE倒存在的技术’}}
但,如果我杀了我的应用程序,一切都停止工作。
如果我重新启动应用程序,我将不会收到'message'event和'onNotificationGCM'将不会被调用。
我创办了一些文章谈到这个问题,但没有成功:
Stackoverflow : Phonegap PushNotification to open a specific app page
有没有人有这个问题的想法?
我想只有'需要message'。 'title'是可选的 – Ajoy
我做了你所说的。 1)在adb logcat中,我可以看到来自gcmservices的一些日志。 2)我的留言数据上有“标题”和“留言”。 3)我设置“delayWhileIdle”为false。但我有同样的问题:( –