Can I send user's current location to server, when app is in background?

Can I send user's current location to server when app is in background. For example: In my app i want to store the user's current location in every 2min and then send his current location to server. Can I do this when the app is in background? Can I send location updates to the server in background mode and how?

Answers


You can since iOS7. You basically need to ask for two background states: location and fetch. In your app you'll register for gps location changes, and store them every time your callback is called. Then you'll register for:

 application:performFetchWithCompletionHandler:

This is usually used to download files in the background, but you can use it to POST your data to a webserver. Just note that you don't have control on the frequency of this call. To test this you can force a fetch operation in the iOS simulator, from the Xcode Debug menu. I was able to track the user position successfully this way. You can find more info in the Apple doc and you'll find a tutorial on the background fetch here


I wrote an open source project that gets the location from ios devices periodically (and also for android, windows phone and java me cell phones). It runs fine in the background. I also have written the server software to store the locations and display the routes with google maps. The project is complete and working and is MIT licensed. It does exactly what you are trying to do:

https://github.com/nickfox/GpsTracker

Make sure you look in the phoneClients directory for ios to see how I get the location periodically. The ios client project also uses AFNetworking which easily allows an app to post updates to a webserver from the background using background tasks.


Covers it pretty well here: https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/RegionMonitoring/RegionMonitoring.html#//apple_ref/doc/uid/TP40009497-CH9-SW1

Depending on authorization your app can be woken up when regions are crossed. Rather than check every two minutes it is when you cross regions generally as the preferred. That saves on battery as it allows apps to be in sleep most of the time.

Also, seems to be spot on: How to wake up an app

Not my area of development, just googling.


Need Your Help

tsql group by get alphanumeric column value with maximum length

sql sql-server sql-server-2012 group-by max

I have a sql view, let's call it SampleView, whose results have the following format.