0

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...

dvkch
  • 1,079
  • 1
  • 12
  • 20

3 Answers3

0

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.

Suhail Patel
  • 13,644
  • 2
  • 44
  • 49
  • Alright, this is uncool, even if I understand the reason why they made it so. But then how could Sparrow mail app work ? Oh and again, can I forget about those limitations for in-house deployment ? I really mean in house, no jailbreak, no ad hoc. Thanks – dvkch Jun 21 '12 at 16:16
  • Sparrow also doesn't have background mode for this exact reason. However since you are not deploying to the app store you could disguise it as a VOIP app and use it's relevant socket methods? (this is what Sparrow tried to do but was rejected from the App Store) http://sparrowmailapp.com/push.php – Suhail Patel Jun 21 '12 at 16:19
  • Oops I looked for this page but didn't find it.... Is disguising it as a VOIP app that easy ? Cannot I create a daemon or something else ? The goal is to take photos in particular places then on the way home it uploads. Maybe geoservices could help ? Again thank you – dvkch Jun 21 '12 at 16:23
0

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.

Chris DeSalvo
  • 913
  • 1
  • 8
  • 10
  • Great answer too. But again, since I'm doing in house deployment which means apple cannot tell me 'no', do I have new options ? – dvkch Jun 21 '12 at 16:22
  • I might want to use GPS events, but how would it be possible to trigger some action in my app based on a geolocation event ? I cannot find this particular information is the SDK doc set. Sorry if this is a newbie question... – dvkch Jun 29 '12 at 14:14
0

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 !

dvkch
  • 1,079
  • 1
  • 12
  • 20