我有 使用cordova 3.5配置的推送插件https://github.com/phonegap-build/PushPlugin.git 。当应用程序在前台时,通知插件回调被调用,一切都按预期工作。
当应用程序处于非活动状态(在后台)时,会收到通知,我可以在通知栏中看到它们,但不会调用回调函数。我的代码基于推送插件中给出的示例。下面是我简化的代码以重现该问题,
initialize : function () {
console.info('NOTIFY Ready to register for push notification.');
var pushNotification = window.plugins.pushNotification;
// Register device with push server
pushNotification.register(gcmSuccessHandler, gcmErrorHandler, {
'senderID': GCM_SENDER_ID,
'ecb': 'onNotificationGCM'
});
}
window.onNotificationGCM = function(notification){
//the beep is invoked 3 times only when the app is in foreground
navigator.notification.beep(3);
console.log('EVENT -> RECEIVED:' + notification.event + '');
}
一天多来,我一直在为这个问题头疼。任何帮助表示赞赏。
更新: 我终于找到了问题所在。我必须清除 dalvik 缓存并重新启动手机。到目前为止发生在我身上两次。似乎是 android 中的一个已知问题,https://github.com/phonegap-build/PushPlugin/issues/35。