相册相机访问

判断相册访问权限

iOS 8 之前

#import 
ALAuthorizationStatus author =[ALAssetsLibrary authorizationStatus];
if (author == kCLAuthorizationStatusRestricted ||
    author ==kCLAuthorizationStatusDenied){
       //没有权限
} else{
      //有限权
}

typedef enum {
   kCLAuthorizationStatusNotDetermined = 0, // 用户尚未做出选择这个应用程序的问候
   kCLAuthorizationStatusRestricted,        // 此应用程序没有被授权访问的照片数据。可能是家长控制权限
   kCLAuthorizationStatusDenied,            // 用户已经明确否认了这一照片数据的应用程序访问
   kCLAuthorizationStatusAuthorized         // 用户已经授权应用访问照片数据
} CLAuthorizationStatus;

iOS 8之后

 #import 
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
if (status == PHAuthorizationStatusRestricted ||
    status == PHAuthorizationStatusDenied) {
       //没有权限
}else{
      //有限权
}

typedef NS_ENUM(NSInteger, PHAuthorizationStatus) {
  PHAuthorizationStatusNotDetermined = 0, // 默认还没做出选择
  PHAuthorizationStatusRestricted,        // 此应用程序没有被授权访问的照片数据
  PHAuthorizationStatusDenied,            // 用户已经明确否认了这一照片数据的应用程序访问
  PHAuthorizationStatusAuthorized         //  用户已经授权应用访问照片数据
} NS_AVAILABLE_IOS(8_0);

两者结合即是

- (BOOL)isCanUsePhotos {

    if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0) {
        ALAuthorizationStatus author =[ALAssetsLibrary authorizationStatus];
        if (author == kCLAuthorizationStatusRestricted || author == kCLAuthorizationStatusDenied) {
            //无权限
            return NO;
        }
    }else {
        PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
        if (status == PHAuthorizationStatusRestricted ||
            status == PHAuthorizationStatusDenied) {
            //无权限
            return NO;
        }
    }
    return YES;
}

判断相机访问权限

iOS7之前都可以访问相机,iOS7之后访问相机有权限设置

 #import 
 #import 

  AVAuthorizationStatus authStatus =  [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
  if (authStatus == AVAuthorizationStatusRestricted ||
     authStatus == AVAuthorizationStatusDenied) {
        //无权限
  }else{
       //有权限
  }

typedef NS_ENUM(NSInteger, AVAuthorizationStatus) {
    AVAuthorizationStatusNotDetermined = 0,// 系统还未知是否访问,第一次开启相机时
    AVAuthorizationStatusRestricted, // 受限制的
    AVAuthorizationStatusDenied, //不允许
    AVAuthorizationStatusAuthorized // 允许状态
} NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;

你可能感兴趣的:(相册相机访问)