In our app we ask for location permission (WhenInUse) on one view that is used to display a map.
If the user choses to disable device location service (ie globally disabled in device settings) and then opens our view in the app, the location permission popup will show. Rinse repeat a few times (turn service back on, go on app, leave app, turn service off, etc.) and after a few times the location permission alert will stop showing.
Anyone know if this is a bug in iOS (happens on iOS 10)?
We could use our own alert that shows when
CLLocationManager locationServicesEnabled = NO
but since we have no control about if/when the iOS location alert pops up, it sometimes happens that they both would show at the same time which is bad UX.
Any known solution to the problem? I have to explain to our QA and manager if this is a bug in iOS.
EDIT:
- (BOOL)negotiateLocationServicePermission:(UIViewController *)context
{
/* Device location service is enabled. */
if ([CLLocationManager locationServicesEnabled])
{
/* App location service is already authorized. */
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse
|| [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways)
{
/* App location service is authorized. Start location updates ... */
[self startUpdatingLocation];
return YES;
}
else
{
/* App location service not yet authorized and status is not determined (aka: first time asking for permission). */
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined)
{
/* Request the location permission from the user. */
if ([self respondsToSelector:@selector(requestWhenInUseAuthorization)])
[self requestWhenInUseAuthorization]; /* iOS 8+ */
else
[self startUpdatingLocation]; /* iOS 7 */
return YES;
}
/* App location service not authorized and previously denied. */
else
{
/* App location service permission was denied before. */
// Show custom alert!
return NO;
}
}
}
/* Device location service is disabled. */
else
{
// Show custom alert!
return NO;
}
}
I don't think this is a bug, this is different AlertView.
If the user accept the location permission once, it's saved, it won't ask him again. But if the location service is disabled, this is a different case scenario.
You can implement it this way :
if ([CLLocationManager locationServicesEnabled]){
NSLog(@"Location Services Enabled");
if ([CLLocationManager authorizationStatus]==kCLAuthorizationStatusDenied){
alert = [[UIAlertView alloc] initWithTitle:@"App Permission Denied"
message:@"To re-enable, please go to Settings and turn on Location Service for this app."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}
So if the user disables the location service from the Settings, the alert view can make a redirection to the Settings page.
This way multiple AlertViews won't show up. It just depends how you want to handle every case scenario like :
Make sure you handle every case, and test it out.
I don't know if I answered your question precisely, I hope it will help for your implementation.
If I remember correctly, the iOS dialog is only issued when authorizationStatus
is undetermined
. if the status is denied
(when only the specific app is denied or the entire location service is disabled) you need to issue your own dialog with a deep link to settings
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.