5

Can i send location updates to my server in background from iOS4?. I want to get users location changes and post it to a server using a web-service call. Main question here is, is it possible to call a web-service or http-post while app is in background?

sach
  • 1,069
  • 4
  • 15
  • 29

2 Answers2

6

Absolutely, and you may want to review this earlier thread when I asked the same question - credit due to @RedBlueThing for providing the key information.

I've written this up as an example on our blog as well. The key to this working is beginBackgroundTaskWithExpirationHandler: without that you won't get reliable results as it will perhaps work some of the time, but not others.

Community
  • 1
  • 1
Roger
  • 15,793
  • 4
  • 51
  • 73
1

Yes. You can basically do anything you want in the background callbacks.

I'd like to add that you should make sure you are aware of the possible impact on battery life, as the antennas may have to be turned on to perform your requests. Perhaps you could store the locations in core data, and post it to the server when the app resumes.

But there's no technical reasons to not do it, and afaik it will pass review too.

August Lilleaas
  • 54,010
  • 13
  • 102
  • 111
  • 1
    The key to reducing battery life impact is to only monitor significant changes which basically looks for cell-tower switching which is something the phone has to do anyway as it moves around. Obviously you still have to spin up the radio in order to post the data, and that does use power, but the significant location algorithm means you won't normally be doing that very much at all and updates are pretty infrequent. Apple suggested this approach to @RedBlueThing in a dev forum so not only will it pass review, it's pretty much the officially sanctioned way of doing it. – Roger Jul 28 '11 at 10:40
  • ..if significant location updates is what you want, that's a good idea indeed :) – August Lilleaas Jul 28 '11 at 11:22