can i get location with GPS while my application is closed? - iphone

I've seen application on iphone called "moves"
the gps is running on background while the application is totaly closed and not working in the background.
how can i get the location of the user and send it to the application while it is closed and not working on background? how could this possible?
what is the function to do that?
thanks

It is possible to get the location while the phone is running in the background (The Google Maps app does this), however running a background thread is a privilege that you must justify to Apple in their review process.
Here is some documentation by Apple for guidelines for running in the background

You register for the significant-change location service.
According to the Apple docs:
If the app starts this service and is then terminated, the system relaunches the app automatically when a new location becomes available.

This is not possible for an App on a non jailbraked iphone. Check again what you really have seen.
Apps can run in the background and get locations. But an app which is closed, can not do anything, since it is not running.
Maybe you have sawn the GPS Arrow in the status bar, staying active. But this disappears after some seconds, as long as no other application uses GPS.

Related

Location Tracking

I have application which is sending tracked data to our hosted server whenever location manager called in background. Its working fine normally.
But issue is when user switched off the iPhone and turn ON it back application is showing GPS icon but application is not giving response.
PS: User have not touch the app or start after restart the app.
Is it possible to get the response from the app after restart the device?
That is because the app is not active after restarting the iPhone. You could add the voip key to UIBackgroundModes as detailed in this SO post (and a sample app on GitHub) to start your app again after restarting the device. However, if you use this app only for tracking the location, Apple will likely reject your submission for making use of the voip-key.
If you use region monitoring, then your app will be automatically started in the background when a user enters or leaves a region, even if the device is turned off and back on. Use region monitoring, see this answer on SO.

How to receive acceleration-related data from the onboard hardware, when application in background mode?

Am developing application for calculate count of user moved steps and draw the user activities in the map. And we are using UIAccelerometer delegate for receive acceleration-related data from the onboard hardware. So I need to receive acceleration-related data when the application in background mode too. Last time one of my application got rejected because of using location service in background, Apple suggested me like "you can only use this background mode if your app truly needs this information to provide value for the user". Kindly suggest the best approach for this application.
You cannot run accelerometer in background.
You can track user's location in background... however, if you just keep tracking it and do nothing with that info.. apple is going to reject it and tell you to just get the lates location when app comes to foreground.
what you can try is.. update the user of total distance covered etc on a regular basis (like run keeper) and this will justify tracking location in background.
But first, you can try appealing to the review board explaining that you need to track location in background because you show entire route travelled by user when app comes to foregraound. and compare this to existing apps like run keeper and if you are lucky apple may approve your application without any changes...
This can easily be done.
What happens in that iOS put your application in halt state when your application is not in running in foreground state.
You just need to register your application for background execution.
Refer :
http://dcraziee.wordpress.com/2013/05/20/background_ios/
Also refer :
iOS background application network access
for apple policies about using location service.Which states that you can use location service in background.

Keep infomed for Device location will Application in Backgroud

I'am developing an application that keep a WebService informed for device location each 5minute (for exemple) :
So when the application leave the foreground execution and enter background I have to lunch a timer who
1 - Update the device location
2 - Send the location to a web service
How can I perform this action ? Or do you know any code exemple that I can follow to achieve this design ?
Thank you for your help !
Doesn't look like anyone gave you a solid answer, so allow me.
There is no iOS approved way of running a 5 minute (or any minute) timer in the background (unless your app is VOIP or music). What you CAN do is register your app as requiring location services in the background (edit the info.plist and add a key Required Background Modes and then add a value App registers for location updates. What this means is your locationManager:didUpdateToLocation:fromLocation: method and corresponding region monitoring/SLC methods will fire on location change, but Timers will not work at all.
The reason why is that timers require a run loop (a thread executing code) to be running and must piggy-back on that thread, but when the app is in the background even when executing code from the LocationManager, the run loop that executes the code almost always finishes before your timer would go off.
Hope this helps!
you cannot do this (on iOS).
(unless your app requests permissions that are meant for Navigation apps)
Hello #Aladdin Gallas,
I have developed a simple application that supports background location updates for iOS and Android in Xamarin.
The app pushes a new location every 2 seconds (you can change it to 5 minutes if you want to).
There is a feature I haven't been able to add; it is to keep the service up when the user closes the app (for iPhone). Other than that, as long as the app is open, even if the phone is locked, the service keeps running.
You can take a look at the application as a reference if it helps.
GitHub Repo

Will an iOS app that monitors signficant location changes be restarted on device reboot?

From the Core Location documentation:
The regions you register with the location manager persist between launches of
your application. If a region crossing occurs while your application is not
running, the system automatically wakes up your application (or relaunches it)
in the background so that it can process the event. When relaunched, all of
the regions you configured previously are made available in the
monitoredRegions property of any location manager objects you create.
Unfortunately, this is unclear as to whether or not the same app will also be relaunched after device reboot in response to a region change.
Will an iOS app that monitors significant location changes in the background still be relaunched, even after a device reboot?
Yes, your app will be launched to respond to the region events even if the phone is restarted, and even if the user did not explicitly run your app after the reboot.
I haven't seen any documentation that spells that out clearly. But this is how it works in a couple of my own apps.
Just to make an update. I know that this is an old question, but I want to confirm that it works on iOS7, even after a reboot.
Check my question here:
Are background mode location and fetch called even after the device restarted in iOS7?

What can I do inside "location" background thread?

For the sake of this question, assume I plan to build a Google Latitude client app for iOS 4.
my app needs to upload the user gps location every two minutes, and also download the user friends locations. - in the background!
my app can't wait to be woken up by the OS on cellular tower switches (because they may only happen after 2 KM, while my app needs constant gps updating), so I understand I can create a thread, similar to the ones GPS navigators use, to run in the background.
I have no knowledge in iPhone programming, I just need to know if my app is feasible.
Will I be able to access the internet from within the background thread (and upload the user gps location), or is it restricted to only sampling the GPS location.
1.
Will Apple approve such an application, or is this type of use forbidden? because my app isn't realy critical such as a gps navigator
Thanks!
As Don said, iOS will send location events to apps that support it. From there, the app can do what it needs to do with the location event.
Background apps can register for one of three options:
Significant changes only: a low-power way to track location that only wakes the app up when there's a "significant" change in location
Standard location services: compatible with all iOS devices that can use location services, allows you specify change in distance, and works in background. However, if the app has been terminated or suspended, iOS won't attempt to relaunch the app.
Continuous location services: allows the program to receive continuous location updates and iOS will not suspend the application when sent to the background.
More info: Executing Code in the Background and Location Awareness Programming Guide
If you take a look at Executing Code in the Background, Apple provides guidelines on what multitasking-aware apps should and shouldn't do.
You will receive the locationManager:didUpdateToLocation:fromLocation: message in your app. In there, you can do whatever you need to, although you should not update the UI or use Open GL if your are in the background.