2

I want to implement long-running background timer which sends user's location to server periodically.

To do this, I set location mode for UIBackgroundModes, and call beginBackgroundTaskWithExpirationHandler when the application goes to background. And for CLLocationManager, I use startUpdatingLocation method (don't want to use significant change, because I need high precision location).

But around 26minutes after the app goes to background, it stops to send location to the server. But the app isn't crashed, so after I bring the app to foreground, it can resume its timer.

26minutes is from experiments, with iOS 6.1, iPhone 5.

Here are some questions,

  1. I can't understand why it suspends after 26mins not 10mins, which is known as time limit for background task.

  2. Before 16mins, backgroundTimeRemaining methods returns double max value. But after 16mins, it decreases from 600, so it suspends the background task after 10mins.

I already tried to call beginBackgroundTaskWithExpirationHandler inside of expiration handler, but no use.

If there's anyone who has a clue for this problem, will be greatly appreciated.

Jaehwa Han
  • 61
  • 2
  • 4

2 Answers2

6

https://github.com/voyage11/Location

Use this code.you can set time interval you want to call it. I have tried many codes, but i found this as most accurate and least battery issue.This is also awesome for background location service. :)

Nikita Khandelwal
  • 1,741
  • 16
  • 25
-1

if you have set UIBackgroundModes successfully,the App can run a long time in the background while you are moving. But, if you stop moving for over 10 minutes(maybe more), the App will be suspended by the system. Your App will be awake if the location updates,but this awake time will be very short,so you must cal beginBackgroundTaskWithExpirationHandler method to handle location update.

Makyen
  • 31,849
  • 12
  • 86
  • 121
czlux
  • 1