ios 查询相册/摄像头/麦克风 的使用权限


www.MyException.Cn  网友分享于:2015-06-21  浏览:0次
 
 
iOS如何判断应用是否开启摄像头权限

AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];  

typedef NS_ENUM(NSInteger, AVAuthorizationStatus) {

AVAuthorizationStatusNotDetermined = 0, //点击允许访问时调用  //用户明确许可与否,媒体需要捕获,但用户尚未授予或拒绝许可。

AVAuthorizationStatusRestricted, 

AVAuthorizationStatusDenied,   //不允许

AVAuthorizationStatusAuthorized   //允许访问 

} NS_AVAILABLE_IOS(7_0);

 

麦克风权限检测:

  1. //检测麦克风功能是否打开  
  2.   [[AVAudioSessionsharedInstance]requestRecordPermission:^(BOOL granted) {  
  3.       if (!granted)  
  4.       {  
  5.           [ViewUtilalertViewWithString:NSLocalizedString(@"麦克风功能未开启",nil)];  
  6.       }  
  7.       else  
  8.       {  
  9.             
  10.           [selfrecord:sender];  
  11.       }  
  12.   }];

 

相册权限检测:需要

 

#import <AssetsLibrary/AssetsLibrary.h> //导入此类和AssetsLibrary.framework框架

  1. int author = [ALAssetsLibrary authorizationStatus];  
  2.             NSLog(@"author type:%d",author);  
  3.             if(author == ALAuthorizationStatusRestricted || author == ALAuthorizationStatusDenied) {  
  4.                 // The user has explicitly denied permission for media capture.  
  5.                 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"无法使用相册"  
  6.                                                                 message:@"请在iPhone的\"设置-隐私-照片\"中允许访问照片。"  
  7.                                                                delegate:self  
  8.                                                       cancelButtonTitle:@"确定"  
  9.                                                       otherButtonTitles:nil];  
  10.                 [alert show];  
  11.                 [alert release];  
  12.                 return;
posted @ 2016-02-24 15:52  fantasy_love  阅读(541)  评论(0编辑  收藏  举报