Checking location service permission on iOS

前端 未结 8 1808
有刺的猬
有刺的猬 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条回答
  •  Happy的楠姐
    2020-12-07 12:57

    -(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
    
        NSLog(@"%@",error.userInfo);
        if([CLLocationManager locationServicesEnabled]){
    
            NSLog(@"Location Services Enabled");
    
            if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusDenied){
             UIAlertView    *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];
            }
        }
     }
    

    Reason behind this, this method will call when your service will be disable the location service. this code is useful for me.

提交回复
热议问题