iOS权限问题

判断相机权限:

NSString *mediaType = AVMediaTypeVideo;
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
if(authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied){
                   //相机权限受限制
}
typedef NS_ENUM(NSInteger, AVAuthorizationStatus) {
    AVAuthorizationStatusNotDetermined = 0,    请问是否授权访问
    AVAuthorizationStatusRestricted,     权限都限制
    AVAuthorizationStatusDenied,    拒绝访问
    AVAuthorizationStatusAuthorized     授权访问
} NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;

 

判断相册权限:

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
    if (status == PHAuthorizationStatusDenied || status == PHAuthorizationStatusRestricted) {
        //相册权限受限制
    }
}
else{
    ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];
    if (status == ALAuthorizationStatusDenied || status == ALAuthorizationStatusRestricted) {
         //相册权限受限制
    }
}

ALAuthorizationStatus 在iOS9之后废弃了,
PHAuthorizationStatus 是ios8新增的替代 ALAuthorizationStatus 的方法。
typedef NS_ENUM(NSInteger, PHAuthorizationStatus) {
    PHAuthorizationStatusNotDetermined = 0, 
    PHAuthorizationStatusRestricted,       
    PHAuthorizationStatusDenied,        
    PHAuthorizationStatusAuthorized        
} NS_AVAILABLE_IOS(8_0);
typedef NS_ENUM(NSInteger, ALAuthorizationStatus) {
    ALAuthorizationStatusNotDetermined 
    ALAuthorizationStatusRestricted 
    ALAuthorizationStatusDenied 
    ALAuthorizationStatusAuthorized 
} NS_DEPRECATED_IOS(6_0, 9_0, "Use PHAuthorizationStatus in the Photos framework instead");

 

你可能感兴趣的:(iOS权限问题)