Javascript 推送通知仅在注销时有效

Javascript 推送通知仅在注销时有效,javascript,android,ios,cordova,push-notification,Javascript,Android,Ios,Cordova,Push Notification,我们有一个接收推送通知的phoengap应用程序。当用户退出应用程序时,推送通知可以正常工作。但当他们登录时,它会中断 我想知道它是否正在向GCM/Apple注册,并在登录时获得新ID或其他信息 我想问题是,我应该什么时候运行下面的代码。此时,它会在用户登录后运行。我应该运行它一次,然后保存ID,再也不运行注册表吗 receivedEvent: function(id) { var pushNotification = window.plugins.pushNotificati

我们有一个接收推送通知的phoengap应用程序。当用户退出应用程序时,推送通知可以正常工作。但当他们登录时,它会中断

我想知道它是否正在向GCM/Apple注册,并在登录时获得新ID或其他信息

我想问题是,我应该什么时候运行下面的代码。此时,它会在用户登录后运行。我应该运行它一次,然后保存ID,再也不运行注册表吗

 receivedEvent: function(id) {
        var pushNotification = window.plugins.pushNotification;

        if (device.platform == 'android' || device.platform == 'Android') {
            pushNotification.register(this.successHandler, this.errorHandler,{"senderID":"1019013414678","ecb":"app.onNotificationGCM"});
        }
        else {

            pushNotification.register(this.tokenHandler,this.errorHandler,{"badge":"true","sound":"true","alert":"true","ecb":"app.onNotificationAPN"});
        }
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);
    },
    // iOS
    onNotificationAPN: function(event) {
        var pushNotification = window.plugins.pushNotification;
        console.log("Received a notification! " + event.alert);
        console.log("event sound " + event.sound);
        console.log("event badge " + event.badge);
        console.log("event " + event);
        if (event.alert) {
            navigator.notification.alert(event.alert);

        }

        if (event.sound) {
            var snd = new Media(event.sound);
            snd.play();
        }
    },
    // Android
    onNotificationGCM: function(e) {
        switch( e.event )
        {
            case 'registered':
                if ( e.regid.length > 0 )
                {
                    console.log("Regid " + e.regid);
                  localStorage.setItem("PushID", e.regid)
                  updateID();
                }
                break;

            case 'message':
                // this is the actual push notification. its format depends on the data model
                // of the intermediary push server which must also be reflected in GCMIntentService.java
                alert(e.message);
                break;

            case 'error':
                alert('GCM error = '+e.msg);
                break;

            default:
                alert('An unknown GCM event has occurred');
                break;
        }
    }

这是我的错误。每次应用程序打开时,我都会运行此代码,它会给我一个新的ID。我只是保留了我原来的ID,它似乎起了作用。

你解决了这个问题吗?是的,每次应用程序打开时,它都会给我一个新的ID,我停止了它,你能详细说明一下吗?如果你能回答你自己的问题“我应该什么时候运行下面的代码”,那肯定对我也有帮助。