user379468
user379468

Reputation: 4039

How to create a background function that is called every n minutes indefinately

This question exists in different flavors on github, but this mine is specific. I'm creating an iPhone app that logs locations. I'm trying to log the location every 5 min even when the app is in the background and when the user is not moving. So far I've tried the following;

Use CoreLocation to fire the events - if the phone is stationary, the location events are not fired, so logging every 4 min in the bg does not work.

Use Perform Fetch to and read last location - this seems to fire when it pleases, can't get it to reliably fire every 5 min

Use a background task and NS Timer havent tried but seems feasable ** since this won't be going in the app store, is there a way to call a bgtask that spins up another bg task before it dies?

**** this app does not need to be approved by apple

Upvotes: 0

Views: 200

Answers (1)

onnoweb
onnoweb

Reputation: 3038

If you need to do this for an in-house app - you're saying the app doesn't need to be approved by Apple - then you can set your app to be a VOIP app. In your info.plist file you set the corresponding background mode and then you can call the UIApplication:setKeepAliveTimeout to tell iOS at what interval you want some background processing time. Minimum interval is 10 minutes.

Upvotes: 1

Related Questions