Wednesday 15 April 2015

iOS long-running background timer with "location" background mode -


I want to implement a long-running background timer that sends the location periodically to the user's location.

To do this, I have set location mode for UIBackgroundModes , and call startBackgroundTaskWithExpirationHandler when the application is in the background And for CLLocationManager , I use the startupdatingLocation method (I do not want to use significant changes, because I need a high precision location).

But for about 26 minutes the app goes back to the background, it stops sending the server to the location. But the app has not crashed, so after I bring the app to the foreground, it can resume its timer.

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

Here are some questions,

  1. I do not understand why this 26mins is not suspended after 10mins, which is the time limit for background work

  2. Before 16mins, backgroundTimeRemaining methods get double maximum value return. But after 16mins, it decreases from 600 , so it is suspended after 10mins, background work is suspended.

    I have already tried to call BackBackgroundTaskWithExpirationHandler inside the end of the handler, but no use.

    If there is someone who has a clue for this problem, then it will be greatly appreciated.

    Use this code. You can set the time interval you want to call. I have tried to do many codes, but I found this the most accurate and least battery issue It's also great for background location service :)

No comments:

Post a Comment