iOS相机,相册,定位,麦克风权限判断

1 相机权限

#import
#import

AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    
    if (authStatus == AVAuthorizationStatusDenied || authStatus == AVAuthorizationStatusRestricted) {
        // 没有权限,弹出alertView
        [self showAlert];
    }else{
        //获取了权限
    }

2 相册权限

#import

ALAuthorizationStatus authStatus = [ALAssetsLibrary authorizationStatus];
    
    if (authStatus == ALAuthorizationStatusDenied || authStatus == ALAuthorizationStatusRestricted) {
        // 没有权限
        [self showAlert];
    }else{
        // 获取权限
    }

3 麦克风权限(录音等)

- (BOOL)canRecord {
    
    __block BOOL bCanRecord = YES;
    
    if ([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending) {
        
        AVAudioSession *audioSession = [AVAudioSession sharedInstance];
        if ([audioSession respondsToSelector:@selector(requestRecordPermission:)]) {
            [audioSession performSelector:@selector(requestRecordPermission:)     withObject:^(BOOL granted) {
                
                bCanRecord = granted;
            }];
        }
    }
    return bCanRecord;
}

4 定位权限

#import 

CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
    
    if (kCLAuthorizationStatusDenied == status || kCLAuthorizationStatusRestricted == status) {
        //没有权限
        [self showAlert];
    } else {
        //获取权限
    }

你可能感兴趣的:(iOS相机,相册,定位,麦克风权限判断)