#import
- (void)getCameraJurisdiction {
NSString *mediaType = AVMediaTypeVideo;// Or AVMediaTypeAudio
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
if(authStatus == AVAuthorizationStatusDenied){
// The user has explicitly denied permission for media capture.
NSLog(@"Denied"); //应该是这个,如果不允许的话
UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"请在设置中允许访问相机" preferredStyle:UIAlertControllerStyleAlert];
//默认只有标题 没有操作的按钮:添加操作的按钮 UIAlertAction
UIAlertAction *cancelBtn = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"取消");
}];
//添加确定
UIAlertAction *sureBtn = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"确定");
}];
//设置`确定`按钮的颜色
[sureBtn setValue:[UIColor redColor] forKey:@"titleTextColor"];
//将action添加到控制器
[alertVc addAction:cancelBtn];
[alertVc addAction :sureBtn];
//展示
[self presentViewController:alertVc animated:YES completion:nil];
}
else {
self.isCameraCanPush = YES;
}
}
- (void)getmMicrophone {
//检测麦克风功能是否打开
[[AVAudioSession sharedInstance]requestRecordPermission:^(BOOL granted) {
if (!granted){
NSLog(@"麦克风没开");
UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"请在设置中允许访问麦克风" preferredStyle:UIAlertControllerStyleAlert];
//默认只有标题 没有操作的按钮:添加操作的按钮 UIAlertAction
UIAlertAction *cancelBtn = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"取消");
}];
//添加确定
UIAlertAction *sureBtn = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"确定");
//设置`确定`按钮的颜色
[sureBtn setValue:[UIColor redColor] forKey:@"titleTextColor"];
//将action添加到控制器
[alertVc addAction:cancelBtn];
[alertVc addAction :sureBtn];
//展示
[self presentViewController:alertVc animated:YES completion:nil];
}else {
self.isSoundCanPush = YES;
}
}];
}
NSURL *url = [NSURL URLWithString:@"App-Prefs:root=Privacy&path=CAMERA"];
if ([[UIApplication sharedApplication] canOpenURL:url]){
if (@available(iOS 10.0, *)) {
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
}else {
[[UIApplication sharedApplication] openURL:url];
}
}