Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic/Cordova iOS - invoke function on app open

Is it possible to invoke a function after applications is re-opened (closed with home button, not closed as a process)?

like image 922
Jack Avatar asked Feb 16 '15 11:02

Jack


1 Answers

Yes, you can do this using by injecting the $ionicPlatform service into either a run block (for the entire app) or into a single controller.

Here is an example of it in a run block:

.run(function($ionicPlatform) {
    $ionicPlatform.on('resume', function(){
        // Do sweet stuff!
    });
}

And here it is in a controller:

.controller(function($ionicPlatform) {
    $ionicPlatform.on('resume', function(){
        // Do sweet stuff!
    });
}

Note that this is really just a wrapper for Cordova's resume lifecycle event. You can see more information about the $ionicPlatform service and the 'on' method in the Ionic framework docs here.

like image 95
JimTheDev Avatar answered Sep 23 '22 16:09

JimTheDev