美文网首页
iOS---常用权限判断

iOS---常用权限判断

作者: 不可雕的板蓝根 | 来源:发表于2018-07-05 15:35 被阅读0次

    权限判断引入头文件

    #import <AVFoundation/AVFoundation.h>
    #import <Photos/PHPhotoLibrary.h>
    #import <CoreLocation/CoreLocation.h>
    
    + (BOOL )authStatusCamara{
        AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
        if (authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied) {
    //        NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
    //        if ([[UIApplication sharedApplication]canOpenURL:url]) {
    //            [[UIApplication sharedApplication]openURL:url];
    //            return NO;
    //        }
            
            NSString* message = [NSString stringWithFormat:@"相机权限受限,请前往设置->%@->相机,打开权限!", APPNAME];
            MessageShow(message);
            return NO;
        }
        return YES;
    }
    
    + (BOOL )authStatusAssets{
        
        PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
        if (status == PHAuthorizationStatusRestricted || status == PHAuthorizationStatusDenied){
            
            NSString* message = [NSString stringWithFormat:@"照片权限受限,请前往设置->%@->照片,打开权限!", APPNAME];
            MessageShow(message);
            return NO;
        }
        return YES;
    }
    
    + (BOOL )authStatusLocation{
        
        CLAuthorizationStatus author = [CLLocationManager authorizationStatus];
        if (author == kCLAuthorizationStatusDenied || author == kCLAuthorizationStatusRestricted){
            
            NSString* message = [NSString stringWithFormat:@"位置权限受限,请前往设置->%@->位置,打开权限!", APPNAME];
            MessageShow(message);
            return NO;
        }
        return YES;
    }
    

    相关文章

      网友评论

          本文标题:iOS---常用权限判断

          本文链接:https://www.haomeiwen.com/subject/xsypuftx.html