Ionic page transition not working to page with push feature

后端 未结 3 1828
情话喂你
情话喂你 2021-01-25 03:41

I implemented android push reception in my app, and it works well as long as the app starts at that page. But if you navigate to the inbox page where the push notifications are

3条回答
  •  时光说笑
    2021-01-25 04:09

    I had similar problem in my app when i was trying to make a REST call at the same time of view transition. this is because $http promise is interrupting view rendering. This can be taken care of if you wrap your $http call in $timeout because $timeout with no time mentioned will put your $http in queue rather than interrupting current task.

    you can do something like

    $scope.$on('$cordovaPush:notificationReceived', handleNotification);
    
    handleNotification = function(event, notification){
        $timeout(function(event, notification) {
                switch(notification.event) {
                    case 'registered':
                        if (notification.regid.length > 0 ) {
                            alert('registration ID = ' + notification.regid);
                            $scope.regid = notification.regid;
                            var user = { user: 'David', type: 'android', token: notification.regid };
                            $http.post('http://172.16.16.101:8000/tokens', JSON.stringify(user));
                        }
                        break;
    
                    case 'message':
                        // this is the actual push notification. its format depends on the data model from the push server
                        //alert('message = ' + notification.message + ' msgCount = ' + notification.msgcnt);
                        alert(JSON.stringify([notification]));
                        var aux = {title:'',message:'',payload: { valor1:true }}
                        $scope.mensajes.push(notification);
                        break;
    
                    case 'error':
                        alert('GCM error = ' + notification.msg);
                        break;
    
                    default:
                        alert('An unknown GCM event has occurred');
                        break;
                }
            });
    }
    

    this is a rough idea that you have to fix and refine to fit your need

提交回复
热议问题