美文网首页
判断是否有权限读取相册或相机

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

作者: WeeverLu | 来源:发表于2016-06-01 15:38 被阅读227次

导入头文件

#import <AVFoundation/AVFoundation.h>
#import <AssetsLibrary/AssetsLibrary.h>

参考代码

// 拍照
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];
    }
}

相关文章

网友评论

      本文标题:判断是否有权限读取相册或相机

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