iOS中获取相册、相机、定位、以及麦克风权限设置
1、判断用户是否获取了相册的访问权限
#import <AssetsLibrary/AssetsLibrary.h>// 获取相册权限
- (void)getPhotoLibraryAuthor {ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];if (status == ALAuthorizationStatusRestricted || status == ALAuthorizationStatusDenied) {UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:nil message:@"请开启相册权限\n 设置 -> 隐私 -> 照片" preferredStyle:UIAlertControllerStyleAlert];[alertVc addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];[self presentViewController:alertVc animated:YES completion:nil];} else {[self openPhotoLibrary];}
}
2、判断用户是否获取了相机的访问权限
#import <AVFoundation/AVMediaFormat.h>
#import <AVFoundation/AVCaptureDevice.h>// 获取相机权限
- (void)getCameraAuthor {AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];if (status == AVAuthorizationStatusRestricted || status == AVAuthorizationStatusDenied) {UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:nil message:@"请开启相机访问权限\n 设置 -> 隐私 -> 相机" preferredStyle:UIAlertControllerStyleAlert];[alertVc addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];[self presentViewController:alertVc animated:YES completion:nil];} else {[self openCamera];}
}
3、判断用户是否获取了麦克风的访问权限
#import <AVFoundation/AVFoundation.h>- (BOOL)getMicrophoneAuthor {__block BOOL canRecord = YES;if ([self.audioSession respondsToSelector:@selector(requestRecordPermission:)]) {[self.audioSession performSelector:@selector(requestRecordPermission:) withObject:^(BOOL granted) {if (granted) {canRecord = YES;} else {canRecord = NO;UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:nil message:@"请开启麦克风访问权限:\n设置 -> 隐私 -> 麦克风" preferredStyle:UIAlertControllerStyleAlert];[alertVc addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];[self presentViewController:alertVc animated:YES completion:nil];}}];}return canRecord;
}
4、判断用户是否获取了定位的访问权限
//检测的是整个的iOS系统的定位服务是否开启
[CLLocationManagerlocationServicesEnabled]//检测当前应用的定位服务是否开启需要通过一下方法来检测
- (void)locationManager:(CLLocationManager*)managerdidFailWithError:(NSError*)error {UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:nil message:@"请开启定位权限:\n设置 -> 隐私 -> 定位服务" preferredStyle:UIAlertControllerStyleAlert];[alertVc addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];[self presentViewController:alertVc animated:YES completion:nil];
}**或者是下面这个可以尝试一下:**- (void)getLocationAuthor {CLAuthorizationStatus status = [CLLocationManager authorizationStatus]; if (status == kCLAuthorizationStatusDenied || status == kCLAuthorizationStatusRestricted) { UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:nil message:@"请开启定位权限:\n设置 -> 隐私 -> 定位服务" preferredStyle:UIAlertControllerStyleAlert];[alertVc addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];[self presentViewController:alertVc animated:YES completion:nil]; }
}
iOS中获取相册、相机、定位、以及麦克风权限设置相关推荐
- IOS中获取各个文件的目录路径的方法和NSFileManager类
转自:http://blog.sina.com.cn/s/blog_5fb39f910101di92.html IOS中获取各种文件的目录路径的方法 iphone沙箱模型的有四个文件夹,分别是什么,永 ...
- android 麦克风权限设置,绝地求生刺激战场麦克风权限怎么设置?刺激战场麦克风权限设置方法[多图]...
绝地求生刺激战场麦克风权限有哪些方法设置?麦克风可以和玩家之间进行沟通,但是有时候开了语音也没有声音,下面就让安卓乐园小编为大家带来,刺激战场麦克风权限设置方法. 绝地求生刺激战场语音怎么没声音 1. ...
- iOS - 中获取各种文件的目录路径的方法
转自:https://www.cnblogs.com/zrr-notes/p/5953445.html 我们的app在手机中存放的路径是:/var/mobile/Applications/4434-4 ...
- chrome修改摄像头权限_如何在Chrome中更改网站的摄像头和麦克风权限
chrome修改摄像头权限 Google Chrome lets you manage which individual sites can have access to your microphon ...
- iOS中获取WiFi的SSID(CNCopySupportedInterfaces())
获取当前设备连接WiFi: ios5之前可以通过读取配置文件获取,ios5以后苹果修改wifi列表文件位置,只有root权限才可以读取. ios4:/System/Library/SystemConf ...
- iPhone PHP获取文件,IOS中获取各种文件的目录路径的方法
iphone沙箱模型的有四个文件夹,分别是什么,永久数据存储一般放在什么位置,得到模拟器的路径的简单方式是什么. documents,tmp,app,Library. (NSHomeDirectory ...
- IOS中CoreLocation框架地理定位
1.CoreLocation框架使用前提: #import <CoreLocation/CoreLocation.h> CoreLocation框架中所有数据类型的前缀都是CL ,Core ...
- (转)IOS中获取各种文件的目录路径的方法
iphone沙箱模型的有四个文件夹,分别是什么,永久数据存储一般放在什么位置,得到模拟器的路径的简单方式是什么.documents,tmp,app,Library.(NSHomeDirectory() ...
- ios中获取各种文件的目录路径方法
2019独角兽企业重金招聘Python工程师标准>>> iphone沙箱模型的有四个文件夹,分别是什么,永久数据存储一般放在什么位置,得到模拟器的路径的简单方式是什么. docume ...
最新文章
- android屏幕分辨率详解 ldpi mdpi hdpi 程序UI自适应 《官方翻译》
- Git命令按人统计提交次数和代码量
- 深圳电信网速测试工具
- 放置奇兵 新 粉石墨
- SpringMVC异常处理机制-异常处理两种方式
- linux中的memory management和page mapping
- SSIA的完整形式是什么?
- Android实现异步处理 -- HTTP请求
- 9203 0409 随堂
- 【java】分布式一致性hash算法
- java.io.IOException: http://XXX provided port:50000 is not reachable
- 套利进阶——简单易行的分级基金套利
- BZOJ4484: [Jsoi2015]最小表示
- debian使用FTP详细配置教程
- c++ 中字符串的字符数与字节数
- ClassNotFoundException,某种类的缺失
- python教学小说05 宽容之心,是容纳世界的神奇变量。
- 六月集训(第21天) —— 堆(优先队列)
- 青春无敌?那只是一瞬间
- vue——数字加逗号分隔
热门文章
- 2019电赛所需仪器设备和主要元器件清单
- IOS如何给VIEW设置2个圆角?set cornerRadius for only top-left and top-right corner of a UIVIEW
- hive中的逻辑运算符 案列_Hive 教程(官方Tutorial)
- 覆盖索引是什么?一篇文章告诉你
- 基金申请-4:如何检索国家基金科研项目?
- [论文评析]Balanced MSE for Imbalanced Visual Regression,CVPR,2022
- python的常见矩阵除法_numpy常用矩阵运算方法【转】
- 使用Tomcat10.0.10搭建一个文件下载服务器
- HostMonitor是一款功能强大的运维管理软件
- Web3的2048,Sui 8192能否打开全链游戏的大门?