简体   繁体   English

恢复或暂停科尔多瓦事件后如何解决?

[英]How to resolve after resume or pause cordova events?

We can listen for the events 'resume' and 'resolve' with the cordova event listeners. 我们可以使用cordova事件监听器监听事件“ resume”和“ resolve”。 In the ionic platform, this corresponds to : 在离子平台上, 这对应于

  $ionicPlatform.on('resume', function() {
    $rootScope.$broadcast('onResume');
  });

  $ionicPlatform.on('pause', function() {
    $rootScope.$broadcast('onPause');
  });

Certain pages of my app require a resolve to take place (see authResolve below). 我的应用程序的某些页面需要进行解析(请参阅下面的authResolve)。

However, how do I call the function resolve again once the user has exited the app (double click home button on iphone) and then returns? 但是,一旦用户退出应用程序(在iPhone上双击主页按钮)然后返回,我该如何再次调用该函数? Like how do you combine the resolve function with the above cordova event listeners? 像您如何将resolve函数与上述cordova事件侦听器结合在一起? Thank you! 谢谢!

app.js (part of) app.js(的一部分)

.config(function($stateProvider, $urlRouterProvider) {
  //
  $urlRouterProvider.otherwise('/auth');

  // 
  var authResolve = function ($q, Auth) {
    var qResolve = $q.defer();
    var AuthObj = Auth.getAuthObj();
    switch (AuthObj.authStatus) {
      case true:
        qResolve.resolve("AUTH_RESOLVE_SUCCESS");
        break
      case false:
        qResolve.reject("AUTH_RESOLVE_UNAUTHORIZED");
        break
      default: 
        qResolve.reject("AUTH_RESOLVE_OTHER", AuthObj);
        break
    };
    return qResolve.promise;
  };

 // REST OF .config

    .state('tab.album', {
    url: '/dash/:albumName',
    views: {
      'menuContent': {
        templateUrl: 'templates/tab-album.html',
        controller: 'AlbumCtrl',
        resolve: {authResolve: authResolve}
      }
    }
  })

})

I'd try this: 我会尝试这样的:

$ionicPlatform.on('resume', function() {
  $state.transitionTo($state.current, $stateParams, {
      reload: true,
      inherit: false,
      notify: true
  });
});

(source: Reloading current state - refresh data ) (来源: 重新加载当前状态-刷新数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM