Location manager stops working after some interval in background - iphone

I m developing an app in which I have to track the LocationUpdate in the Background as well as in the Foreground but after some time interval in the Background the app stops updating the Location. When I take it back to Foreground it starts again and when I put it in background after some time interval it stops again.
I am not able to find the issue please help me if possible.

You have to specify that your app need location updates when in background in plist
Here is apple docs Getting Location Events in the Background
and here is a tutorial for this.
And I would recommend you to read Location Awareness Programming Guide

disable distance filter
set desired Accuracy to best
use - (void)startUpdatingLocation
Now in ios6: there is
locationManager:didUpdateLocations:
in ios5 there is
locationManager:didUpdateToLocation:fromLocation:
the first delivers the locations buffered in the background and keeps your application sleeping and wakes it up with a sequence of fixes, while the ios5 method delivers the location all of the time.

Related

How to get current location latitude and longitude if application running in Background?

I am Working with CLLocation manager,
I have implemented startUpdatingLocation method for getting current location latitude and longitude.
I got latitude and longitude of current location if application running Foreground but, when application running in Background it's not work.
Please suggest me how i got the current location latitude and longitude if application running in Background.
i just found answer in stackoverflow from this link:-
How do I get a background location update every n minutes in my iOS application?
Found a solution to implement this with the help of the Apple Developer Forums. I did the following:
Specify location background mode
Use an NSTimer in the background by using UIApplication:beginBackgroundTaskWithExpirationHandler:
In case n is smaller than UIApplication:backgroundTimeRemaining it does works just fine, in case n 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.
Note: Did loose some time by testing this in the simulator where it doesn't work, works fine on my phone.
Get currcnt Location in backround Specify location background mode in plist.

An event should invoke a method while the app is on Background-iphone

I need to invoke a method each time an event is occurred even if the application is in the background.
In my case -each time I get a picture from the server I want to present it,
and if the application is in the background I want it to reEnter the foreground and present the picture.
Is it possible? if not, what is the nearest alternative?
Thanks,
Asaf
i thnk this is not possible, but use notifications to do this that application will become active when it receive notification.
further see these threads
iPhone OS 4.0.x - transition from background to foreground
How to bring app to foreground programmatically

Start CLLocationManager while in background

Is it possible to "suspend" the cllocationmanager while in the background?
I'm trying to stop the manager then restart it at a specific time all while in the background. Is this possible? I tried stopping the manager and starting a nstimer, but it doesn't work because nstimer does not run while in the background.
My objective is to have the manager run during certain time intervals, "suspend" during certain time intervals, and start after the suspend time is up in order to preserve battery life.
Thanks for the help!
The short answer is: No.
The long answer is: Apple has thought of that and has a solution for you.
You should read about App States and Multitasking and look for "Tracking the User’s Location" subtitle.

Background location updates for iOS display GPS icon the entire time

My app runs significant location change updates in the background. However the GPS display icon never turns off..even when app is in the background. Is there a way to use location manager with Significant location change in the background and have the GPS icon NOT display continuously? My users don't understand that it is only periodically obtaining location coordinates and instead think its constantly running in background and thus deleting app thinking its too power intensive. Please help.
I believe that any use of CoreLocation will prompt the location arrow. That includes any of the geofencing CLRegion use, -startMonitoringForSignificantLocationChanges, and -startMonitoringForLocation. I think that is Apple's safeguard that something is using your GPS, even in limited use.
That arrow will be visible till you unregister your application from significant change. But I faced problem, what I can't fine point where I can do this. In my case will be best to unregister on application kill, but with multitasking there is no such ability to handle this moment to unregister.

Executing code in background

I have a application that periodically (via an NSTimer) asks for the users location using locationManager:startUpdatingLocation I want the locationManager to run in the background so have entered "UIBackgroundModes = location" in the info.plist file.
My question is I am not seeing the results I expected, am I right in thinking that when I press the home button the application delegate calls "applicationDidEnterBackground" but although locationManager is allowed to continue my NSTimer is getting suspended (and as a consequence its not calling startUpdatingLocation to periodically query the devices position). Any ideas / solutions would be much appreciated ...
Gary.
All NSTimers are invalidated when entering the background. You need check via the CLLocationManager for any changes.
Just keep the startUpdateLocation running, you delegate will receive any major changes of the location.
When running in the background, you will only receive location changes based on cell towers.
If you read the documentation for -applicationDidEnterBackground: you'll find that yes, your timers are invalidated. Furthermore, the iOS Application Programming Guide tells you exactly how to track location from the background.