码迷,mamicode.com
首页 > 移动开发 > 详细

iOS权限问题

时间:2016-03-18 20:09:44      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:

判断相机权限:

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权限问题

标签:

原文地址:http://www.cnblogs.com/huahua0809/p/5293098.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!