小编典典

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?


阅读 356

收藏
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