Checking location service permission on iOS

前端 未结 8 1802
有刺的猬
有刺的猬 2020-12-07 12:32

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

8条回答
  •  抹茶落季
    2020-12-07 12:38

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

提交回复
热议问题