Location manager icon still displayed even when I call stopUpdatingLocation - ios

Even though I called stopUpdatingLocation on my location manager, the location manager icon is still on the top right of my iPhone. Why hasn't it stopped?

There are several reasons why the location arrow on your phone may still be on even after calling stopUpdatingLocation.
For one, another app on your phone may currently be using your location.
Another possibility is that you enabled significant location change monitoring using the startMonitoringSignificantLocationChanges method but forgot to turn this off using the stopMonitoringSignificantLocationChanges method. Apps that are monitoring significant location changes will display a solid arrow in the status bar in the same way apps that are using standard location updates do.
Of course it's also possible that you are for whatever reason incorrectly calling stopUpdatingLocation and you actually are still getting location updates from a location manager. To check if this is happening wait several minutes after calling stopUpdatingLocation and go to Settings>Privacy>Location Services and find your app. If there is a solid purple arrow next to your app then your app is indeed currently using location services and something most likely went wrong when calling stopUpdatingLocation. However if there is a solid gray arrow, this just signifies that your app has recently used location services and it's likely that you did correctly stop getting updates. Another way to check if you correctly turned off location updates is by calling your CLLocationManager's location property and checking its timestamp property to make sure that it is not recent. If the timestamp is greater than the timestamp at which you called stopUpdatingLocation then you know something is wrong.

The icon you see at the top is not locationManager, is the location service of the device. If you deactivate in settings no longer appears.

Related

Do not show location service icon in status bar but still use background updates

I'm looking for some solution to handle the problem:
If I use locationManager.requestAlwaysAuthorization() there're appears an location icon in status bar and never disappears, so, it is the problem - user can think that my app drain battery, but it's not.
So, when I use .requestWhenInUseAuthorization() I can't call didUpdateLocations function to update location even I add fetch background update, the #selector does not allow to call that method.
I want my app get location updates in background without always showing the location icon in the status bar. How can I update location by fetch?
So, when I use .requestWhenInUseAuthorization() I can't call didUpdateLocations function
Yes you can. If you go into the background when you are updating locations, you can continue to update locations. What you cannot do is start updating locations from the background.
I want my app get location updates in background
Use deferred location updates or location monitoring. This will keep your use of sensors to the minimum. Otherwise, the user's impression that you are using up the battery while in the background is entirely justified.

Blue banner '%MyApp% is Using Your Location' for app that uses location services only when active

In my app I'm updating user location every time when app becomes active. I stop CLLocationManager once updated location is received or in applicationWillResignActive:.
In Info.plist there is a NSLocationWhenInUseUsageDescription with appropriate description.
If app is activated and then immediately moved to background, blue banner saying that '%MyApp% is Using Your Location' appears for less then a second. This banner gets hidden as soon applicationWillResignActive: is called.
I've noticed the same problem in Google Maps, but not in Apple Maps.
Is there a way to get rid of this banner completely? Is there anything else I should do to make iOS happy? I do not want it to freak out my users and prevent them from using cool features that require location.
You have probably set location as Background mode in your info.plist. If you remove that, then the blue bar won't appear anymore.
Or, you can use requestAlwaysAuthorization instead of requestWhenInUseAuthorization on CLLocationManager (and provide the related NSLocationAlwaysUsageDescription in the info.plist file), and then it will not appear either.
In my case, my app is using location in the background in some cases, and I would like the blue bar to appear when that is the case. But I do not want it to appear when exiting the app without location in background. As far as I know that is not possible to achieve (I've asked about it here).
EDIT: Note that starting with iOS-9, you can make sure that the blue bar only appears when the user actually wants the app to use the location in the background. See this answer.
If you want to get access to the user's location with CLLocationManager, the app will need to show that banner and the user will need to press "Allow". If they don't do that, your location manager won't be able to detect the user's location.
Apple's Maps is a special case because it's a first party app.

Region monitoring when device is off

I have a client requirement to monitor a region (say MyHome). To alert the user when he leaves MyHome and reaches back to the location. I can handle it pretty easily using the region crossing delegate methods:
locationManager:didEnterRegion:
locationManager:didExitRegion:
My question is, what will be the scenario if my device is off when I am at MyHome location. I leave the location MyHome, move to a different place and switch on my mobile. Will I get the locationManager:didExitRegion: delegate method fired when I launch the app back and thus will be able to notify that I am away from the region. OR will I have to do anything else to get this possible?
First of all monitoring region is not made for such small area to monitor. You may not get actual results. Now, the answer of your question, yes. It is possible. When you will start your device, you will have delegates method to get hit.

ios background location services arrow disappears when not moving

I built this app which is tracking the users position even when running in background. I use the CLLocationManagers method
startUpdatingLocation
I set the CLLocationManager to
desiredAccuracy=kCLLocationAccuracyNearestTenMeters
distanceFilter=250
Everything works fine in foreground and in background. But when I don't move the device for a longer period (hours) I can see that the location arrow disappears. When I switch back to my app I can see that the arrow comes back immediately and that the app did NOT crash. Is this a "feature" of the LocationManager I don't know? Did the LocationManager went into some kind of "standby"? This should NOT be an issue with the app running not in foreground since I can travel with it for an hour and it gives me a perfect track.
Yes, this is a feature. As given in the documentation location manager object manages power aggressively by turning off hardware when it is not needed. Turning off GPS hardware can lead to significant power savings.

CLLocationManager don't stop

Dear fellow developers,
I am trying hard to find a solution for my problem regarfing CLLocationManager.
I use a CLLocationManager instance in my Application. If the user selects the Home button on the device or terminates the application I want the location services to stop.
Therefor I call [self.locationManager stopUpdatingLocation]; - But this somehow doesn't work. The application enters the background and the small location arrow in the upper right corner of the status bar don't disappear. Even if I add [self.locationManager release] or self.locationManager.delegate = nil; - the location tracking don't stop :-/
It only disappears if I go to my device settings and switch off location services for the app. Whenever I switch back to location service enabled I immediately get a purple colored arrow next to the switch toggle and the icon reappears in the status bar.
My question is how can I turn off location services when the app enters the background or is terminated?
Thanks a lot in advance and have a nice day :-)
Your location is disabled. The location service icon "meaning" has changed on iOS 5. Take a look at this question: https://apple.stackexchange.com/questions/27463/why-is-the-location-services-icon-always-present
I Quote the answer:
It's a new feature in ios 5 called "region Monitoring"
The reason it's active even if the app is closed is that this feature
runs in iOS 5 core and notifies all apps that are registered when they
have entered or left a specific geo-fence.
Reminders does that when you use a location based reminder.
Although the location icon appears at all time. This actually has very
minimal impact on the battery due to apple really optimizing this
feature by using cell and wifi mostly.
Your app is working ok. The system behaviour is the one who changed.
You do it the right way. When entering background, it's ok if some delegate methods are called for some seconds. That should stop.
Where do you stop the location updates ? Are you sure it is triggered ? If yes, are your delegate method called even if the visual indicators tell something else ?
Are you sure you don't trigger a method that reactivate the location update after you have stopped it (because for example you can receive some updates even after stopped).
For instance if you started monitoring a significant location change, then you should unsubscribe from it with the corresponding pair method. If you are using region enter, then until you unsubscribe, the system will notify your delegates.

Resources