Can startMonitoringForRegion wake my app up, and start gps tracking? - iphone

In Apple's developer portal , it states that startMonitoringForRegion:desiredAccuracy: will eventually wake up my app (even if it's killed) and send the Core location delegate a message.
The question is : Is it possible to start GPS tracking (precise tracking, instead of cell-tower based tracking) after receiving this message (even if my app is in the background ) ?!

Well , I searched for it , and it appears as it does wake up the app.
I can also use startUpdatingLocation to get more frequent (and even GPS) updates.

Related

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.

Use of Standard location service for tracking traveled distance in a foreground/background app

I have to develop a kind of GPS navigation application that needs to constantly keep track of the position of the user, which is moving by car.
In the specific, I don't have to display the current location on a map but just to record its position with the best possible precision in order to calculate the total distance traveled.
Of course the application needs to continue its work in background if the user switch to another app, a phone call come in or something like that…
From the tests I have made and from what I have learned from this useful post (and from the documentation), it seems to me that the best choice in this case is the Standard location service, with the application configured with the UIBackgroundModes = location in the .plist file.
In this way it will continue to receive the location updates even if in background and it will never be suspended by the OS (this is actually true only if [locationManager startUpdatingLocation] has been called). This is also confirmed by this guys.
I have personally verified that is true simply by running the app with Instruments and the Memory monitor module where you can see the various flags about the app states, putting the app in background first with UIBackgroundModes set to location and startUpdatingLocation active, and after without it.
1) I'm now wondering what to do when the app is terminated when it is tracking the position. I don't want to loose any location updates so I need to wake up it again whenever a new update is available.
The documentation say:
Important: The applicationWillTerminate: method is not called if your
app is currently suspended.
But because in my case it will be never suspended (it will stay in background but not suspended), my logical conclusion is that applicationWillTerminate will be always called and so I could register for a Significant location update or Region monitoring inside of this method in order to be waked up and then restart the Standard location service.
Is applicationWillTerminate the right place to put this code?
2) An application working in background but not suspended could be terminated by the OS for no other reasons than a very low memory condition or for my app don't properly respond to a memory warning? (the user could also manually close it). I was concerned if applicationWillTerminate wouldn't be called in some way.
3) Could Apple not approve an app which constantly use the standard location services in background because of its quick battery drain?
Have you ever had approve problems for similar apps?
since you are asking many questions which you shoukd not do here, i cam give you only aswrs to a part of it.
if the app is terminated, then you cannot restart it anymore.
This is usually the case when the user terminates the app.
Dont worry Apple ( ios) will not terminate your app. your app will not use much memory, games with huge bitmap graphics are more likely to be termin.
evry gps app will drain the bat. that is not a reason for not aproving.
suspended means that app is not in background mode, it is sleeping. you will not receive Gps, so there is no need to call you on terminate. you have to save data before, see the apple docu on background modes and app life cycle.

iphone: backgrounded app sync webservice

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

Register local notification from background

I have a situation where I have to present alert while my app is in background.
So I was thinking that the solution is Local notification.
But the problem is that, I want to show that alert only when user has crossed a particular predefined location point.
So I have to show the notification without any registration for it in Foreground(Or you can say register the local notification in background).
Is it doable ?
Please help.
Yes, you can let your run in the background while you still receive location updates.
You have to the add location to UIBackgroundModes in your apps info.plist;
And any instance of CLLocationManager will keep receiving location updates.
But be aware that this could drain the battery of the iPhone really fast, so it's a good idea to only monitor major location changes.

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.