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];

    }

}

上面这个相机方法 运气不好基本都得被拒绝,可以处理以下那个字符串,让苹果检测不出来 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值