判断是否有权限读取相册或相机

导入头文件

#import 
#import 

参考代码

// 拍照
if (buttonIndex == kSourceTypeCamera) {
    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    if(authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied) {        
        NSLog(@"您没权限访问相机");
    }    
    else {
        // 显示界面     
        [self showImagePickerWithSourceType:UIImagePickerControllerSourceTypeCamera];    
    }
}
// 相册
else if (buttonIndex == kSourceTypePhotoLibrary) {
    ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];    
    if (author == ALAuthorizationStatusRestricted || author == ALAuthorizationStatusDenied){        
        NSLog@"您没权限访问相册");    
    }    
    else {
        // 显示界面
        [self showImagePickerWithSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
    }
}

你可能感兴趣的:(判断是否有权限读取相册或相机)