Reputation: 7004
We can listen for the events 'resume' and 'resolve' with the cordova event listeners. 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).
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? Like how do you combine the resolve function with the above cordova event listeners? Thank you!
app.js (part of)
.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}
}
}
})
})
Upvotes: 1
Views: 1596
Reputation: 2641
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)
Upvotes: 1