onPause And onResume handling in ionicFramework

I want to send the geolocation to server in every 5 minutes whenever app goes in backgroud ? How to handle this in ionic ?

Use the pause and resume event of cordova, combined with https://docs.angularjs.org/api/ng/service/$interval to execute a function every x minutes.

Take a look at the example on the angularjs page.
on pause event -> store the $interval to variable (accessable in both events).
on resume event -> cancel $interval with $interval.cancel(variable)


Please clarify how to do it . My question is how to get notified app in on pause in Ionic

+1 need that info too

Yeah use cordova/phone events in your app:
Add the eventlisteners for “pause” and “resume” with the functionality i described in my first post.

Do not know, what you still need.

Sorry maybe you could clearify it a bit.

When ever app goes in background i wanna send geo location to server . Now i am able to handle pause and resume events . I wanna configure this https://github.com/christocracy/cordova-plugin-background-geolocation in ionic app . how to do it ?

this has nothing to do with ionic.

It is a general usage problem.
And for usage of this plugin:
There is a full javascript example in the readme of the plugin.

In you base- or main controller you could listen to the events and start tracking.
Or you do this in angularjs.run method.

But are you really need this plugin?

You could use the general cordova geolocation plugin.
And call in your $interval

window.navigator.geolocation.getCurrentPosition(function(location) {

Is there any other alternative of this plugin ,I wanna track his geo location when app goes in background in every 5 minutes . I got struck on this . $interval will not work in background.

did any1 got it working??

pause event does not track location(lat, long) when app in background

First of all: why using $timeout? navigator.geolocation.watchPosition provides periodically updates, or did I miss something?

You must enable background mode, e.g. by using this plugin https://github.com/katzer/cordova-plugin-background-mode. But I couldn’t get it to work properly. In my case, the app is killed anyway. Apple store compliance is also a problem. Perhaps you cannot just activate background mode without using any native functions that execute background tasks.

So https://github.com/christocracy/cordova-plugin-background-geolocation could be a good alternative. Isn’t it possible to just use

document.addEventListener('pause', service.onPause, false);

inside an angular service?

@bengtler sir plz help me i try to getting location continuously after 30 minute and store in sqlite.
It is working properly if online,
but if i am offline then application work in background process getting locations for each 30 minute & these all records getting same locations when i am opening application but i want different locations & time for each minute according to geolocation.