简体   繁体   中英

running an NSTimer in the background of a multitasking iPhone app to turn location service on/off

i am attempting to make an app that records an accurate location every 10 minutes.

the problem with this is that when running is best mode, the battery drains really quickly.

i would like a timer to turn of the location service, have didUpdateToLocation get a good location, turn of location service and then wait for the timer again.

i have tried a million things- but my NSTimer always gets frozen when put in background mode.

interestingly, didUpdateFromLocation can turn location service off, and if you use significantChangeUpdate you can use didUpdateToLocation to turn location service back on when the user passes a triangulation boundry- and record locations to coredata-

so in theory the only thing stopping me getting this thing running is an NSTimer in a thread that doesnt get frozen, ever.

i read some documents that said you CAN do simple things in the background beyond VOIP, location, audio. does anyone have any experience getting a thread running that doesnt get frozen? i know everyone thinks it can't be done- from my research it is possible, but i just cant figure it out.

advice based on any experience getting a thread running in the background beyond VOIP, Audio, location would be much appreciated

thanks guys, dave-

The answer to this question has an alternative hack where you use re-use the applicationDidEnterBackground event to loop back on itself, each time re-starting a thread where you can do some work

iPhone - Backgrounding to poll for events

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM