Javascript 未激发ngCordova notificationReceived事件

Javascript 未激发ngCordova notificationReceived事件,javascript,android,angularjs,cordova,ngcordova,Javascript,Android,Angularjs,Cordova,Ngcordova,我正在ionic(angular+cordova)上开发应用程序,为了访问cordova插件,我使用ngCordova(angular的cordova插件实现)。我在安卓系统中遇到了一个问题 我在GCM中通过senderID成功注册了一个用户: $cordovaPush.register({ senderID: MY_SENDER_ID }); 我从$cordovaPush:notificationReceived事件中获得一个regid: $rootScope.$on('$cordo

我正在ionic(angular+cordova)上开发应用程序,为了访问cordova插件,我使用ngCordova(angular的cordova插件实现)。我在安卓系统中遇到了一个问题

我在GCM中通过senderID成功注册了一个用户:

$cordovaPush.register({
    senderID: MY_SENDER_ID
});
我从$cordovaPush:notificationReceived事件中获得一个
regid

$rootScope.$on('$cordovaPush:notificationReceived', function(event, notification){
    if(notification.event === 'registered'){
         if(notification.regid.length > 0) {
             ServerCommunicatorService.makeRequest('POST', 'auth/update-gcm-id', {gcm_id: notification.regid});
         }
     }
});
然后我有一个这样的监听器,在前台显示通知并在控制器中执行一些操作:

$rootScope.$on('$cordovaPush:notificationReceived', function(event, notification){
    if(notification.event === 'message'){
        $cordovaToast.show(notification.message, 'long', 'center');
        $rootScope.$broadcast('notificationReceived', notification);
    }
});
最后一个问题是:在成功注册之后,当我从服务器发送通知时,我得到了它们(我是前台)。如果我通过点击设备上的Home(主页)按钮来设置应用程序的背景,我会收到一个状态栏通知。从将我的应用程序带到前端的状态中选择该通知,我将在事件处理程序中获得该通知。既然现在一切都好了。但是当我完全退出应用程序并从服务器发送notif时,我会在状态栏中看到它。我点击它,我的应用程序正在重新启动,在此之后,我在状态栏中获得所有通知,但无法在侦听器中获得它们

在文件中说:

最后,如果您通过点击主页上的后退按钮完全退出应用程序,您仍然可能会收到通知。触摸通知托盘中的通知将重新启动应用程序,并允许您处理通知(COLDSTART)。在这种情况下,将在传入事件上设置coldstart标志


有什么问题吗?提前谢谢

好的解决方案是每次应用程序启动时注册(即使在触摸通知托盘中的通知之后)