Overview
My compagny is asking me to release an application that can check location of the device every two hours. The app would send these location data through a TCP/IP socket to my server and then receive information accordingly to these very data (straight away, and through the same TCP/IP socket). So I'm not trying to make my application running in background mode continuously (which, actually, seems to be a hot topic in iOS, and it's also not suitable for my project).
Question
In order to be reliable, what is the best practice to achieve this? So, I would like to know:
- Since my app is suspended (= inactive), does Apple allow to open a socket to send location when it's woken up by
didUpdateToLocation
? - How long do I have to perform my send/receive task via my socket?
- Should I create a real background task with
beginBackgroundTaskWithExpirationHandler
and use the 10 minutes allowed by Cocoa to perform my send/receive task? - It is possible (and allowed by Apple) to ask for a 10 mins background task every 2 hours, without human interaction (ie. the user should re-open the app, etc)?
What I achieved/found so far
- I added the
location
key in myInfo.plist
to be able to run thedidUpdateToLocation
handler when my app is inactive. - I am able to send and received data through a socket I have opened when my application was in foreground (= active).
- I tried to check the
backgroundTimeRemaining
whendidUpdateToLocation
is called. I got a very large result number, which seems to be normal because, at this point, theapplicationState
is not inUIApplicationStateBackground
but inUIApplicationStateActive
.
These points are not very clear in the official documentation, and I did not found topics related to my specific case.
Thanks for your help.