iOS App跳转权限设置
开启照相机
#import <AVFoundation/AVFoundation.h>
- (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(@"确定");
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}];
//设置`确定`按钮的颜色
[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(@"确定");
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}];
//设置`确定`按钮的颜色
[sureBtn setValue:[UIColor redColor] forKey:@"titleTextColor"];
//将action添加到控制器
[alertVc addAction:cancelBtn];
[alertVc addAction :sureBtn];
//展示
[self presentViewController:alertVc animated:YES completion:nil];
}else {
self.isSoundCanPush = YES;
}
}];
}
标红为核心跳转方法,但是只支持iOS10 或以上,iOS10 以下处理 如下
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];
}
}
上面这个相机方法 运气不好基本都得被拒绝,可以处理以下那个字符串,让苹果检测不出来