iOS 权限获取大全

//相册权限头文件
#import <AssetsLibrary/AssetsLibrary.h>
//判断是否有权限
ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];
if (author == AVAuthorizationStatusRestricted || author ==AVAuthorizationStatusDenied){
       //无权限
       UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"相册打开失败" message:@"请打开 设置-隐私-照片-伊健康诊所 来进行权限设置" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
       [alert show];
                
       return;
}

//相机权限头文件
#import <AVFoundation/AVCaptureDevice.h>
#import <AVFoundation/AVMediaFormat.h>
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied)
{
       //无权限
       UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"相机打开失败" message:@"请打开 设置-隐私-相机-伊健康诊所 来进行权限设置" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
       [alert show];
                
       return;
}

 

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

 

//麦克风权限

//头文件
#import <AVFoundation/AVAudioSession.h>
+ (BOOL)canRecord
{
    __block BOOL bCanRecord = YES;
    if ([[[UIDevice currentDevice] systemVersion] compare:@"7.0"] != NSOrderedAscending)
    {
        AVAudioSession *audioSession = [AVAudioSession sharedInstance];
        if ([audioSession respondsToSelector:@selector(requestRecordPermission:)]) {
            [audioSession performSelector:@selector(requestRecordPermission:) withObject:^(BOOL granted) {
                bCanRecord = granted;
            }];
        }
    }
    return bCanRecord;
}

 

//定位权限


CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
 if (kCLAuthorizationStatusDenied == status || kCLAuthorizationStatusRestricted == status) {
        [self showHint:NSLocalizedString(@"location.open","please open location")];
        return;
}

 

posted @ 2016-03-25 11:18  木易的博客  阅读(830)  评论(0编辑  收藏  举报