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);
麦克风权限检测:
- //检测麦克风功能是否打开
- [[AVAudioSessionsharedInstance]requestRecordPermission:^(BOOL granted) {
- if (!granted)
- {
- [ViewUtilalertViewWithString:NSLocalizedString(@"麦克风功能未开启",nil)];
- }
- else
- {
- [selfrecord:sender];
- }
- }];
相册权限检测:需要
#import <AssetsLibrary/AssetsLibrary.h> //导入此类和AssetsLibrary.framework框架
- int author = [ALAssetsLibrary authorizationStatus];
- NSLog(@"author type:%d",author);
- if(author == ALAuthorizationStatusRestricted || author == ALAuthorizationStatusDenied) {
- // The user has explicitly denied permission for media capture.
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"无法使用相册"
- message:@"请在iPhone的\"设置-隐私-照片\"中允许访问照片。"
- delegate:self
- cancelButtonTitle:@"确定"
- otherButtonTitles:nil];
- [alert show];
- [alert release];
- return;