"Always" location permission... only used occasionally but always showing arrow? - ios

I've found that if you have the "Always" location permission on iOS for an app... even without initializing the CLLocationManager, it always shows the location arrow in the status bar unless the app is "force quit" using the task switcher.
I'm sure that this is on purpose for full disclosure, but it's not accurate considering the location isn't being used. Is there a mistake here that's causing the arrow to display (again, CLLocationManager is NOT initialized) or is this behavior normal these days in iOS 10 since the app could suddenly request location at any point?

The permission states that the app can request the location in the background.
iOS gives this as full-disclosure to the user. They can then visit privacy settings for Location Services and see a colour-coded indicator for a more accurate depiction of when location updates were made.

Related

iOS // CLLocationManager // didFailWithError is triggered with kCLErrorDenied while there are permissions

I have a navigation app that supports CarPlay connection.
When running with CarPlay, some users report that they appear to not have GPS connection.
Looking at the logs I noticed that on app launch we're getting didFailWithError with error code kCLErrorDenied, so according to Apple's recommendation we stop updating location.
This comes immediately after receiving locationManagerDidChangeAuthorization with kCLAuthorizationStatusAuthorizedWhenInUse with accuracy=0.
In this flow we also check CLLocationManager.locationServicesEnabled which returns true, CLLocationManager.authorizationStatus which returns kCLAuthorizationStatusAuthorizedWhenInUse and CLLocationManager.accuracyAuthorization which returns CLAccuracyAuthorizationFullAccuracy.
Users also confirm that they did give location permissions to the app and had location services enabled, also this issue was resolved after a few restarts of the app.
All the cases I encountered were on CarPlay using iOS 16.
Any idea why kCLErrorDenied could be triggered when there are location permissions?
Just in case someone else encounters this issue - this happens when we start location updates while the app is still in the background and we only have permissions for "While Using".
This is more prominent on CarPlay since it's possible to go to the home screen and disconnect. When reconnecting the app would wake up while in the background and try to start updating location.
The solution was to only start updating location when the app is in active state.

Why is CLLocationManager giving me the wrong authorization status?

I'm building a running-based app in Swift that requests the user's location. For the sake of this question, let's just assume the app runs only on iOS 13+. Shortly after launching the app, we prompt the user for location access via the CLLocationManager method: requestWhenInUseAuthorization().
However, this app actually needs access to the user's location all the time, so only being able to request "When In Use" location access (per iOS 13) restricts the UX (other apps like Zenly and Snapchat do this as well since getting constant location updates improves the experience for their users and/or their friends).
After prompting for the location permission, we then grab the latest location authorization status. If that value is not equal to authorizedAlways (and it won't be unless the user changes that value in his/her Settings app), we present a new screen basically telling the user, "Since this is a running app, we really need your location all the time, so please go to settings and change the permission to 'Always' since we can't do it for you."
The issue I'm running into here is that when listening for updates on the CLLocationManagerDelegate method: locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus), sometimes that method provides the incorrect location authorization status.
Specifically, after a user selects "When In Use" and runs the app a few times, the value returned from that delegate method frequently reads as "Always," even though the Settings app on the phone still reflects the original, unchanged value ("When In Use").
Has anyone run into this before and, if so, do you have any ideas on what might cause it or how to fix it? Happy to provide more info on my setup. Thanks.

Xamarin iOS Geolocator Background Service Dying after about 30 mins

I am currently using the Xamarin geolocation plugin found here:
https://github.com/jamesmontemagno/GeolocatorPlugin
To perform location services in an app I am building using Xamarin Forms (PCL).
I believe I have added in the relevant permission settings to allow for this.
The GPS works great while the app is active and locked (but with app in the foreground). However when the app is pushed to the background on iOS by clicking the "home" button, it still tracks the user and highlights the "App is Using Your Location" message as I would expect, however after a certain amount of time between 30-40 minutes, this message disappears, and the GPS appears to stop tracking the user until they bring the app back to the foreground.
Once the app has been brought to the foreground, it can be backgrounded once again for another 30-40 minutes to repeat the cycle.
I have ensured that the locator object allows background updates:
public static Plugin.Geolocator.Abstractions.IGeolocator locator;
locator = CrossGeolocator.Current;
locator.AllowsBackgroundUpdates = true;
locator.DesiredAccuracy = 20;
A call to .PausesLocationUpdatesAutomatically shows that this is false (which I believe is the default).
Edit
I have the following keys to info.plist:
NSLocationWhenInUseUsageDescription
NSLocationAlwaysUsageDescription
And enabled background location updates:
However I have not enabled background fetching as Girish has in the answers, is this something I need to do?
Please check whether you have enabled the background mode for location update.

iOS8 and upgrading location authorisation from WhenInUse to Always

I have a setting that is shown to the user on first run, and depending on this setting the app will either call requestAlwaysAuthorization or requestWhenInUseAuthorization. If the user said no to this setting and later on changes it to yes, I want the app to try and "upgrade" the location authorisation to Always, but I don't get a popup. Is this possible?

How to get IOS to ask users whether they want to allow application to use their location everytime?

If we try to access the user's location, iOS will tell the user that our application wants to use their location.
If I do this
[locationManager startUpdatingLocation];
An alert will show.
However, that only happens once.
It looks like some variable or default must have been set up once that display pops out.
How do I reset those default so that next time my app wants to use location users will be asked again?
Google map can displays that again and again.
It's Apple that asks them for permission, not you
Translation: You don't have any control over that part of the process. The little popup:
is only shown by Apple when you first ask for it - so the user always feels in control. After they accept for the first time, Apple assumes they are OK with your app getting their location information from their device, and won't show it again*.
*Unless they specifically go into Settings and disable Location Services for you app.
It's only showed on the first time and there's nothing you can do to change that. What you can do is ask your users to allow it on settings.
You can check if your app has permissions by checking:
[CLLocationManager locationServicesEnabled]
From the docs:
The user can enable or disable location services from the Settings application by toggling the Location Services switch in General.
You should check the return value of this method before starting location updates to determine whether the user has location services enabled for the current device. If this method returns NO and you start location updates anyway, the Core Location framework prompts the user to confirm whether location services should be reenabled.

Resources