user7388
user7388

Reputation: 1741

get alert for current location every time

I am trying to get device current location using CLLocationManage. I set my method to get location on button click. I can get location successfully but when I get alertview with message "APPNAME would like to use your current location?" with two buttons, "Dont Allow" and "Ok". and I click on "Dont Allow". Then whenever I click on button and I cant get that alertview again to get current location, so I am not able to get the location. So is it possible to get alertview everytime when I click on my button to get location?

Upvotes: 0

Views: 677

Answers (3)

user4234
user4234

Reputation: 1527

The selected answer is correct, for the user.

However, if you're a programmer and you want user to be notified with the alert, you should call

[singleton.locationManager startUpdatingLocation];

This will automatically pops the alert when location services are disabled every time I think as you wish.

A common mistake is to check whether location update is enabled and don't bother calling startUpdatingLocation when it's not.

If that's the case, then the alert will not shows up.

Upvotes: 1

BhushanVU
BhushanVU

Reputation: 3455

Adding this answer so you can more efficiently handle that scenario.

There is no way to force current location permission dialog again, but what you can do is trap its status that user has denied use of location in your app using CLLocationManagerDelegate,

- (void)locationManager:(CLLocationManager*)aManager didFailWithError:(NSError*)error
{
    switch([error code])
    {
    case kCLErrorDenied: // Location access denied
    NSLog(@"Sorry, this app needs to access your current location... ");
    UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"" message:@"Sorry, this 
    app needs to access your current location. You can navigate to settings in your 
    phone > privacy >location services, over there you can see services are off for you 
    application. You can turn it on to give permissions"  
    delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
    //show the alert view
    [myAlert show];
    break;

    case kCLErrorNetwork: // received n/w error
    NSLog(@"Network error occurred");
    }
}

Upvotes: 1

abdus.me
abdus.me

Reputation: 1819

When you click on "don't allow" button on alert, Location permission for your application is restricted.

You can navigate to settings in your phone > privacy >location services, over there you can see services are off for you application. You can turn it on to give permissions

Upvotes: 3

Related Questions