Question

I know this question may be a little bit common and over asked but I cannot find any precise information... so :

Is it possible to have some kind of thread running when the app is in background so I can perform basic sync with my webservice ?

App is in background : I mean the user clicked the Home button, or switched to another app basic sync : photo upload and download with AFNetworking. I know it has method to continue an HTTPRequest while app is in background, but this is not my point.

My goal would be to make some kind of sync manager, reading a list of photos to update created while the user was on the app, and perform those changes.

I know that the manager could be killed by the OS, but since my server uses atomic transfers it is not a problem. I just need a way to relaunch it... Push ?

I think apps like Google Latitude or Mail and those kind of apps uses what I am looking for but I cannot find any relevant details on it. And using iOS5 is not a problem but waiting for iOS6 would not be a solution.

Thank you for your replies !

PS : well I almost forgot. the app is designed for an enterprise program, so maybe rules are different ? I don't think there is any check for in-house deployment so it might lead to new possibilities...

Was it helpful?

Solution 3

Found it !

Using Suhail Patel 's link on Apple's Multitasking Guide I added the voip tag to UIBackgroundModes in Info.plist and use setKeepAliveTimeout:handler: method of UIApplication to relaunch it if needed once the app is going to sleep.

I hope this will help a lot of you !

Of course this app won't be allowed to be on the App Store but for in house development this is in my opinion the best way to do so.

Thanks everyone for showing me the right direction !

OTHER TIPS

Apple's Mail client has a background daemon which keeps it running but you can't have that with your own applications. Once an app enters a background state, it must halt it's operations. You can request for a little more time when backgrounded to finish off any transfers or writes to disk (see the Executing a Finite-Length Task in the Background section on Apple's Multitasking Guide)

Google Latitude has events generated based on location. This is a special type of backgrounding introduced by Apple for certain types of applications (see Implementing Long-Running Background Tasks section on Apple's Multitasking Guide) but this can't be used for HTTP syncing. It can only be used for audio, location, voip, newstand content, bluetooth and external hardware attachments.

Push doesn't seem like a solution because it only generates an alert. It doesn't trigger any action until the user triggers the opening of the notification.

You'll want to read Tech Note 2277 Networking and Multitasking.

Basically you have a couple of options:

If you can convince Apple that your app is a VoIP app then you can register a VoIP socket and the OS will resume your background app whenever there is activity on that socket.

Your main option though is to register a background task for any outstanding activity that you have to do when your app is put in the background. You typically get 10 minutes to finish up that work.

Mail is a special app with privileges you don't get.

Apps like Latitude typically register themselves for location updates, specifically to be woken up when there are major geo-position changes. Apps that record GPS tracks do similar things.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top