美文网首页
ios中应用授权判断及跳转系统授权设置

ios中应用授权判断及跳转系统授权设置

作者: 浅_若清风 | 来源:发表于2017-12-25 17:12 被阅读0次

前言:最近做的IM项目测试那边有要求提高用户体验,添加相机等授权设置,用以前的方法发现实现不了了,上网查了一下,发现IOS10以后方法改变了,在此记录一下。

一、权限判断及代码实现跳转
1、AppDelegate里定义

-(void)alertCamera:(NSString *)messageStr{
    UIAlertView *alertCamera = [[UIAlertView alloc] initWithTitle:@"相机功能不可用" message:messageStr delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"授权", nil];
    [alertCamera show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex==0) {
       
    }else{
        [self Adjusting_system_settings];
    }
}
//跳转系统权限设置( iOS10之后不允许跳转到设置的子页面,只允许跳转到设置界面)
-(void)Adjusting_system_settings{
    if (IOS10) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
    } else {
        NSURL *url = [NSURL URLWithString:@"prefs:root=Privacy&&path=CAMERA"];
        if ([[UIApplication sharedApplication] canOpenURL:url]) {
            [[UIApplication sharedApplication] openURL:url];
        }
    }
}

2、在用到的类导入头文件#import <AVFoundation/AVFoundation.h>,.m里调用方法

//权限判断
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
 if (authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied) {
      [AppDelegate alertCamera:@"无权限,请先在设置中为该软件授权相机服务,然后重试!"];
      return ;
 }else{
 }
lADPBbCc1UICgV7NB1bNBCE_1057_1878.jpg 二、进入TARGTS的info进行配置URL Schemes,如下图 setting.png

相关文章

网友评论

      本文标题:ios中应用授权判断及跳转系统授权设置

      本文链接:https://www.haomeiwen.com/subject/yxnlgxtx.html