一尘不染

Checking location service permission on iOS

swift

How can I check if location service is enabled for my app?

I have 2 storyboards and I want to check location service. If location service
enabled for my app, I want to launch map storyboard with location. Otherwise,
I want to launch another storyboard. How can I do programmatically?


阅读 311

收藏
2020-07-07

共1个答案

一尘不染

This is the correct.

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];
    }
}
2020-07-07