1

Я внедрил прием Android в моем приложении, и он работает хорошо, пока приложение начинается на этой странице. Но если вы перейдете на страницу «Входящие», где реализованы push-уведомления, переход не работает.Ионный переход страницы не работает на страницу с функцией push

Переходный процесс прошел без внедрения push.

Интересно, возникла ли у кого-то аналогичная проблема с реализацией функций.

.controller('BuzonMenuCtrl', function($scope, $window, $state, $ionicPlatform) { 
    $scope.botonBuzon = function(){ 
    $state.go('buzon'); 
    }; 
}) 

.controller('BuzonCtrl', function($scope, $rootScope, $window, $ionicActionSheet, $ionicPopup, $state, $http, dataFactory, pushFactory) { 

    // Activacion de la funcionalidad push 
    pushFactory.funcionalidadPush(); 

} 

factorys.js

.factory('pushFactory', ['$rootScope','$http','$state','$ionicLoading','$ionicPlatform','$cordovaPush','dataFactory', 
          function($rootScope,$http,$state,$ionicLoading,$ionicPlatform,$cordovaPush,dataFactory) { 

    /* Objeto del factory */ 
    var fac = {}; 

    fac.funcionalidadPush = function(){ 
    if (ionic.Platform.isAndroid()){ 
     var androidConfig = { 
     "senderID": "94XXXXXXXXXX", 
     "ecb": "casosPush" 
     }; 

     $rootScope.data.pushplatform = "gcm"; 
     alert('Entro en modo Android'); 

    }; 

    if (ionic.Platform.isIOS()){ 
     alert('Entro en modo iOS'); 
    }; 

    $ionicPlatform.ready(function() { 
     $cordovaPush.register(androidConfig).then(function(result) { 
     // Success 
     }, function(err) { 
     // Error 
     }) 

     window.casosPush = function (notification) { 
     switch(notification.event) { 
      case 'registered': 
      if (notification.regid.length > 0) { 
       alert('registration ID = ' + notification.regid); 
       $rootScope.data.token = notification.regid; 

      } 
      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); 
      $rootScope.mensajes.push(notification); 
      break; 

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

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

     // WARNING: dangerous to unregister (results in loss of tokenID) 
     $cordovaPush.unregister(options).then(function(result) { 
     // Success! 
     }, function(err) { 
       // Error 
     }) 

    }, false); 
    }; 


    return fac; 

}]); 

App.js

angular.module('notPush', ['ionic', 'ngCordova', 'notPush.controllers']) 

.run(function($ionicPlatform) { 
    $ionicPlatform.ready(function() { 
    if(window.cordova && window.cordova.plugins.Keyboard) { 
     cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
    } 
    if(window.StatusBar) { 
     StatusBar.styleDefault(); 
    } 
    }); 
}) 

.config(function($stateProvider, $urlRouterProvider) { 

    $stateProvider 

    .state('splash', { 
    url: '/splash', 
    templateUrl: 'templates/splash.html', 
    controller: 'SplashCtrl' 
    }) 

    .state('buzonMenu', { 
    url: '/buzonMenu', 
    templateUrl: 'templates/buzonMenu.html', 
    controller: 'BuzonMenuCtrl' 
    }) 

    .state('buzon', { 
    url: '/buzon', 
    templateUrl: 'templates/buzon.html', 
    controller: 'BuzonCtrl' 
    }) 

    // If none of the above states are matched, use this as the fallback: 
    $urlRouterProvider.otherwise('/buzonMenu'); 

}); 

EDIT

Как было предложено в комментариях я попытался

$window.location.reload(true); 

, который не делает ничего, кроме сделать экран мигает, а также

$state.go($state.current, {}, {reload: true}); 

, который пытается установить перезагрузить страницу, но только в коррумпированном государстве, он загружает белый фон и кнопки (без цвета), но больше ничего.

EDIT 2 Некоторые пояснения:

  1. Код для уведомления толчка записывается внутри контроллера buzon_page, что страница, которая испытывает проблемы.
  2. Когда я говорю «переход не работает» Я имею в виду, что страница не загружается, но все предупреждения этой страницы все еще запущены, а токен Push еще сохраняется. Визуальная проблема, представление не загружается.
  3. Проблема не связана с HTTP-вызовами, поскольку они в настоящее время прокомментированы.

EDIT 3

Я переместил код уведомления на заводе, а не иметь его внутри контроллера (как это должно быть, я думаю), но нет никаких улучшений.

Я добавляю результат adb logcat во время выпуска. Есть 2 вещи, которые Cought моего внимания:

  1. Это показывает «ReferenceError: опции не определен» на factorys.js
  2. Это показывает некоторый OpenGLRenderer вопрос.

    1219    AudioTrack W AUDIO_OUTPUT_FLAG_FAST denied by client 
    2531    PushPlugin V execute: action=register 
    2531    PushPlugin V execute: data=[{"senderID":ID DELETED FOR PRIVACY ISSUES,"ecb":"casosPush"}] 
    2531    PushPlugin V execute: jo={"senderID":ID DELETED FOR PRIVACY ISSUES,"ecb":"casosPush"} 
    2531    PushPlugin V execute: ECB=casosPush senderID=ID DELETED FOR PRIVACY ISSUES 
    2531   GCMRegistrar D resetting backoff for ID DELETED FOR PRIVACY ISSUES 
    1219 InputMethodManager.. W Window already focused, ignoring focus gain of: [email protected] attribute=null, token = a 
               [email protected] 
    2531   GCMRegistrar V Registering app ID DELETED FOR PRIVACY ISSUES of senders ID DELETED FOR PRIVACY ISSUES 
    2531 SystemWebChromeCli.. D file:///android_asset/www/lib/ionic/js/ionic.bundle.js: Line 20243 : ReferenceError: options is not defined 
    2531 SystemWebChromeCli.. D at file:///android_asset/www/js/factorys.js:214:31 
    2531 SystemWebChromeCli.. D at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:44687:19 
    2531 SystemWebChromeCli.. D at Object.ionic.Platform.ready (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:2120:9) 
    2531 SystemWebChromeCli.. D at Object.self.ready (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:44685:26) 
    2531 SystemWebChromeCli.. D at Object.fac.funcionalidadPush (file:///android_asset/www/js/factorys.js:166:20) 
    2531 SystemWebChromeCli.. D at new <anonymous> (file:///android_asset/www/js/controllers.js:440:15) 
    2531 SystemWebChromeCli.. D at invoke (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:12821:17) 
    2531 SystemWebChromeCli.. D at Object.instantiate (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:12829:27) 
    2531 SystemWebChromeCli.. D at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:17098:28 
    2531 SystemWebChromeCli.. D at self.appendViewElement (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:48110:24) 
    2531    chromium I [INFO:CONSOLE(20243)] "ReferenceError: options is not defined 
    2531    chromium I at file:///android_asset/www/js/factorys.js:214:31 
    2531    chromium I at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:44687:19 
    2531    chromium I at Object.ionic.Platform.ready (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:2120:9) 
    2531    chromium I at Object.self.ready (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:44685:26) 
    2531    chromium I at Object.fac.funcionalidadPush (file:///android_asset/www/js/factorys.js:166:20) 
    2531    chromium I at new <anonymous> (file:///android_asset/www/js/controllers.js:440:15) 
    2531    chromium I at invoke (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:12821:17) 
    2531    chromium I at Object.instantiate (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:12829:27) 
    2531    chromium I at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:17098:28 
    2531    chromium I at self.appendViewElement (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:48110:24)", source: file:///android_asset/www/lib/ionic 
               /js/ionic.bundle.js (20243) 
    1604     GCM D GcmService start Intent { act=com.google.android.c2dm.intent.REGISTER pkg=com.google.android.gms cmp=com.google.android.gms/.gcm.GcmServi 
               ce (has extras) } com.google.android.c2dm.intent.REGISTER 
    2531 GCMBroadcastReceiver V onReceive: com.google.android.c2dm.intent.REGISTRATION 
    2531   GCMRegistrar V Setting the name of retry receiver class to com.plugin.gcm.CordovaGCMBroadcastReceiver 
    2531 GCMBroadcastReceiver V GCM IntentService class: com.plugin.gcm.GCMIntentService 
    2531 GCMBaseIntentService V Acquiring wakelock 
    2531 GCMBaseIntentService V Intent service name: GCMIntentService-GCMIntentService-1 
    2531   GCMRegistrar V Registering receiver 
    2531 GCMBaseIntentService D handleRegistration: registrationId = TOKEN DELETED FOR PRIVACY ISSUES, error = null, unregistered = null 
    2531   GCMRegistrar D resetting backoff for ID DELETED FOR PRIVACY ISSUES 
    2531   GCMRegistrar V Saving regId on app version 10 
    2531  GCMIntentService V onRegistered: TOKEN DELETED FOR PRIVACY ISSUES 
    2531  GCMIntentService V onRegistered: {"event":"registered","regid":TOKEN DELETED FOR PRIVACY ISSUES} 
    2531    PushPlugin V sendJavascript: javascript:casosPush({"event":"registered","regid":TOKEN DELETED FOR PRIVACY ISSUES}) 
    2531 GCMBaseIntentService V Releasing wakelock 
    2531   EGL_emulation W eglSurfaceAttrib not implemented 
    2531   OpenGLRenderer W Failed to set EGL_SWAP_BEHAVIOR on surface 0xa4cdd7e0, error=EGL_SUCCESS 
    1219    AudioTrack W AUDIO_OUTPUT_FLAG_FAST denied by client 
    1219 InputMethodManager.. W Window already focused, ignoring focus gain of: [email protected] attribute=null, token = 
               [email protected] 
    
+0

Это не проблема с плагином! Прочитайте это [ответ] (http://stackoverflow.com/a/25206754/1761793) – Ajoy

+0

Это проблема с плагином, потому что плагин с уведомлением о плагинах Кордовы - это тот, который дает мне головную боль. И спасибо за ваше предложение, но, к сожалению, это не сработает. Я отредактирую вопрос с результатами. –

+0

(Мой плохой. Я ошибался, давайте начнем снова). Что вы подразумеваете под страницей, где реализованы push-уведомления? Не является ли регистрация PN в 'platformReady'? Если есть что-то еще, обновите свой пост соответствующим кодом. Также, когда вы говорите, что переход не работает, есть ли какие-либо ошибки? – Ajoy

ответ

1

Я решил проблему благодаря помощи в комментариях, так что я Здесь я напишу решение.

Комментарий предложил это code, чтобы уведомления о нажатии были активированы сразу же после запуска приложения.

Я добавлю здесь свой код на всякий случай, переменные оповещений и $ rootScope предназначены для тестирования.

/* 
    app.js 
*/ 
angular.module('notPush', ['ionic', 'notPush.controllers', 'notPush.factorys']) 

.run(function($ionicPlatform,$rootScope) { 
    $ionicPlatform.ready(function() { 

    if(window.cordova && window.cordova.plugins.Keyboard) { 
     cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
    } 

    if(window.StatusBar) { 
     StatusBar.styleDefault(); 
    } 

    $rootScope.mensajes = []; 

    // Push code 
    try{ 
     var pushNotification = window.plugins.pushNotification; 
    } catch (ex){ 

    } 
    var successfn = function(result){ 
     alert("Success: " + result); 
    }; 
    var errorfn = function(result){ 
     window.alert("Error: " + result); 
    }; 
    window.casosPush = function(notification){ 
     switch (notification.event){ 
     case 'registered': 
      if (notification.regid.length > 0){ 
      alert('registration ID = ' + notification.regid); 
      } 
      break; 

     case 'message': 
      alert(JSON.stringify([notification])); 
      $rootScope.mensajes.push(notification); 
      break; 

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

     default: 
      alert('An unknown GCM event has occurred'); 
      break; 
     } 
    }; 
    try{ 
     pushNotification.register(
     successfn, 
     errorfn, 
     { 
      "senderID": "94XXXXXXXXXX", 
      "ecb"  : "window.casosPush" 
     } 
    ); 
    } catch(notification){ 

    } 
    }); 
}) 

.config(function($stateProvider, $urlRouterProvider) { 

    $stateProvider 

    .state('splash', { 
    url: '/splash', 
    templateUrl: 'templates/splash.html', 
    controller: 'SplashCtrl' 
    }) 

    .state('registro', { 
    url: '/registro', 
    templateUrl: 'templates/registro.html', 
    controller: 'RegistroCtrl' 
    }) 

    .state('buzonMenu', { 
    url: '/buzonMenu', 
    templateUrl: 'templates/buzonMenu.html', 
    controller: 'BuzonMenuCtrl' 
    }) 

    .state('buzon', { 
    url: '/buzon', 
    templateUrl: 'templates/buzon.html', 
    controller: 'BuzonCtrl' 
    }) 

    .state('detallesSimple', { 
    url: '/detallesSimple', 
    templateUrl: 'templates/detallesSimple.html', 
    controller: 'DetallesCtrl' 
    }) 

    .state('detallesDoble', { 
    url: '/detallesDoble', 
    templateUrl: 'templates/detallesDoble.html', 
    controller: 'DetallesCtrl' 
    }) 

    .state('detallesWV', { 
    url: '/detallesWV', 
    templateUrl: 'templates/detallesWV.html', 
    controller: 'DetallesWVCtrl' 
    }) 

    // If none of the above states are matched, use this as the fallback: 
    $urlRouterProvider.otherwise('/splash'); 

}); 
0

У меня была аналогичная проблема в моем приложении, когда я пытался сделать REST вызов в то же время вид перехода. это связано с тем, что обещание $ http - прерывание представления рендеринга.Это можно позаботиться, если вы завернете свой $ http-вызов в $ timeout, потому что $ timeout без указанного времени будет помещать вашу очередь $ http в очередь, а не прерывать текущую задачу.

вы можете сделать что-то вроде

$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; 
      } 
     }); 
} 

это грубая мысль, что вы должны исправить и усовершенствовать, чтобы соответствовать вашим потребностям

+0

Спасибо, но это не сработало. @hawk –

1

Образец кода из работающего ионного проекта. В качестве примера для инициализации PushPlugin.

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'); 
}); 

При условии здесь только в том случае, суть становится недоступной.