1

I'd like to know if is possible to send asynchronous connections when an app is in background. The reason for this is because I need to send the user's location (get from Core Location) to update a database in a remote server everytime the location changes, even if the app is not in foreground.

Do I have to set any permission for this? Does Apple rejects apps processing connections when app is in background?

Thanks in advance!!

Srikar Appalaraju
  • 71,928
  • 54
  • 216
  • 264
CainaSouza
  • 1,417
  • 2
  • 16
  • 31

2 Answers2

4

iOS provides multitasking API's i.e. even if your app is in background, some of its API's can be accessed. These services are -

  1. Local Notifications
  2. Background Audio
  3. Background Tasks
  4. Background Location

So you can definitely send location updates using CoreLocation when the app is not in foreground.

This link - iOS multitasking has code to start your service when app in background. Step by step instructions

  • Specify location background mode
  • Use an NSTimer in the background by using UIApplication:beginBackgroundTaskWithExpirationHandler:
  • In case x time is smaller than UIApplication:backgroundTimeRemaining it does works just fine, in case x is larger, the location manager should be enabled (and disabled) again before there is no time remaining to avoid the background task being killed. This does work since location is one of the three allowed types of background execution.

SOURCE - How do I get a background location update every n minutes in my iOS application?

Community
  • 1
  • 1
Srikar Appalaraju
  • 71,928
  • 54
  • 216
  • 264
  • Even send NSURLConnections through Core Location delegate methods? – CainaSouza Dec 06 '12 at 16:20
  • Have you tested this? The answer below says it's not possible. I was thinking that I could do like @Zerto suggests, i.e., store all the values with CoreData and send connection when app is in foreground. – CainaSouza Dec 06 '12 at 16:43
  • all that you need is to send location updates to your backend servers and process them. yes this is possible, I have done this. I was trying to find the code but cant remember where I put it... – Srikar Appalaraju Dec 06 '12 at 16:50
0

Here, from the apple documentation (http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4-SW47)

There are several ways to track the user’s location in the background, most of which do not actually require your app to run continuously in the background:

-The significant-change location service (Recommended)

-Foreground-only location services

-Background location services

But you cannot send request, as the only possible things to do are : -audio -location -voip -newsstand -Accessories & blutooth connection

So I guess you could store all your location, and send it with NSURLConnection once the app goes to foreground again

Community
  • 1
  • 1
Zerto
  • 41
  • 3