// 判断 麦克风的权限
#import <AVFoundation/AVCaptureDevice.h>
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
switch (authStatus) {
case AVAuthorizationStatusNotDetermined:
//没有询问是否开启麦克风
NSLog(@"没有询问");
break;
case AVAuthorizationStatusRestricted:
//未授权,家长限制
NSLog(@"家长限制");
break;
case AVAuthorizationStatusDenied:
//玩家未授权
NSLog(@"玩家未授权");
break;
case AVAuthorizationStatusAuthorized:
//玩家授权
NSLog(@"授权开启");
break;
default:
break;
}
主动去申请马克风权限
#import <AVFoundation/AVCaptureDevice.h>
AVAudioSession *session = [AVAudioSession sharedInstance];
[session performSelector:@selector(requestRecordPermission:) withObject:^(BOOL granted) {
if (granted) {
NSLog(@"打开授权");
}
else {
NSLog(@"拒绝授权");
}
}
];
网友评论