判断权限是否有权限:
- (void)AuthorityToJudge:(id)sender
{
[[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {
if (granted) {
// 用户同意开启麦克风权限
NSLog(@"用户第一次允许了打开麦克风权限");
//进行麦克风的操作
[self RECMicBtnClicked];
} else {
// 用户不同意开启麦克风权限
NSLog(@"用户第一次没有允许打开麦克风权限");
//弹窗,提示用户跳转到设置页面设置权限
[self PermissionToRequest];
}
}];
}
- (void)PermissionToRequest
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"此功能需要您开启麦克风权限,请前往设置中开启" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"下次开启" style:UIAlertActionStyleDefault handler:nil]];
[alert addAction:[UIAlertAction actionWithTitle:@"立即开启" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if([[UIApplication sharedApplication] canOpenURL:url]) {
NSURL*url =[NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:url];
}
}]];
[self presentViewController:alert animated:YES completion:nil];
}