0

I have an app that is used for tracking van drivers. I need to be able to get the location (x&y) every 30 seconds or so. I have a method and a timer that allows me to do this.

I was wondering how (if at all possible) I can have this working regardless of whether the app is active or not?

LC 웃
  • 18,888
  • 9
  • 57
  • 72
Alec.
  • 5,371
  • 5
  • 34
  • 69

2 Answers2

1

I've recently started messing around with core-location so my knowledge my not be bullet-proof.

If the app is is still active but only in the background then as long as you set the allowsBackgroundLocationUpdates to true then you will get updates. But this could become battery consuming, it could go on until your battery dies.

You may want to avoid constant location checking by setting: pausesLocationUpdatesAutomatically to true.

However if you do set it to true then if your driver stops at a location for too long(I don't know what means too long) then the app would stop completely from tracking location until you bring the app to foreground again. I'm saying that based on:

Important For apps that have in-use authorization, a pause to location updates while in the background ends access to location updates until the app returns to the foreground and is able to restart location services. If you do not wish location updates to stop entirely, consider disabling this property and changing location accuracy to kCLLocationAccuracyThreeKilometers when your app moves to the background. Doing so allows you to continue receiving location updates in a power-friendly manner.

So it's a little tricky. You may want to set pausesLocationUpdatesAutomatically to true but then if your business requirements allow...do something like stopUpdatingLocation() after 1hr of app being in background to stop location updates completely.

mfaani
  • 33,269
  • 19
  • 164
  • 293
0

Yes, this is possible.

If your iOS app must keep monitoring location even while it’s in the background, use the standard location service and specify the location value of the UIBackgroundModes key to continue running in the background and receiving location updates. (In this situation, you should also make sure the location manager’s pausesLocationUpdatesAutomatically property is set to YES to help conserve power.) Examples of apps that might need this type of location updating are fitness or turn-by-turn navigation apps.

For more information, check out the Location and Maps Programming Guide.

Taylor M
  • 1,855
  • 1
  • 14
  • 20