Ionic page transition not working to page with push feature

后端 未结 3 1830
情话喂你
情话喂你 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:05

    A sample code from a working Ionic project. As an example for how PushPlugin should be initialized.

    var exapp = angular.module('exapp',
                      ['ionic',
                       'ui.select2',
                       'exapp.controllers',
                       'exapp.services']);
    
    exapp.run(function($ionicPlatform, $state, Notifications, geo) {
        $ionicPlatform.ready(function() {
        try{
            var pushNotification = window.plugins.pushNotification;
        } catch (ex){
    
        }
        var successfn = function(result){
            // window.alert("S: " + result);
        };
        var errorfn   = function(result){
            // window.alert("E: " + result);
        };
        window.onCB = function(e){
            switch (e.event){
            case 'registered':
            if (e.regid.length > 0){
                localStorage.setItem('registration_id', e.regid);
            }
            break;
            case 'message':
            if (e.foreground){
                navigator.notification.beep(1);
            }
            $state.go('app.notifications');
            break;
            }
        };
        try{
            pushNotification.register(
            successfn,
            errorfn,
            {
                "senderID": "191919191919191",
                "ecb"     : "window.onCB"
            }
            );
        } catch(e){
    
        }
        });
    });
    
    // States
    exapp.config(function($stateProvider, $urlRouterProvider) {
        $stateProvider
    
        .state('app', {
            url: "/app",
            abstract: true,
            templateUrl: "templates/menu.html",
            controller: 'AppCtrl'
        })
    
        .state('app.profile', {
            url: "/profile",
            views: {
            'menuContent': {
                templateUrl: "templates/profile.html",
                controller: "ProfileCtrl"
            }
            }
        })
    
        .state('app.login', {
            url: "/login",
            views: {
            'menuContent' :{
                templateUrl: "templates/login.html",
                controller: 'AuthCtrl'
            }
            }
        });
    
        // if none of the above states are matched, use this as the fallback
        $urlRouterProvider.otherwise('/app/profile');
    });
    

    Provided here just in case the gist becomes unavailable.

提交回复
热议问题