简体   繁体   中英

How to ask permission from user for second time to allow to access the current location?

In my app, if the user not allowed to access their current location, I can recieve that message in the following method

- (void)locationManager:(CLLocationManager*)aManager didFailWithError:(NSError*)anError
{
    switch([anError code])
    {
       case kCLErrorLocationUnknown: 
        break;

        case kCLErrorDenied:
        {
           UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Access Denied" message:@"You didn't allow to access your current location" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
            [alert show];
          break;
        }
    }
 }

How to ask the user permission for the second time?

I searched and got the answer NO, If the user wants the app to access his/her location, how he/she set the app to use their current location?

Is deleting the app and download another one the only solution?

Is this just me or what? There are several questions like this. Each of which are answered by what the user should do to reenable the location service instead of what the the programmer should do to get that precious consistent alert.

call

[singleton.locationManager startUpdatingLocation];

That's actually what pops the alert.

If you don't call it, then the alert doesn't show up.

If you check first if it's enabled and then call it only if it's enabled, then the alert doesn't show up.

I spent weeks figuring this out. There is no info whatsoever about this in internet.

I think Yes. Deleting the app and download another one is the only solution as that alert message asking user's permission to access location settings is not getting fired by the app but by iPhone OS and hence in my opinion you can't ask it programatically.

I think you can turn on Location Services from device Settings -> Location Services tab.. See the image below

在此输入图像描述

Update: When location services is off for an app, the location manager will fire error with error code kCLErrorDenied then you can show an alert to user to Turn On location services from settings..

Or, you can use the following code too

if (![CLLocationManager locationServicesEnabled])

您可以在设备设置 - >隐私 - >位置中手动重置位置,然后重新启动应用程序。

This need to be done by users.

in ios 7: Settings->General->Restriction->turn on if not->Under privacy -Location services

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM