iOS中获取相册、相机、定位、以及麦克风权限设置
来源:互联网 发布:淘宝商城秒杀女装 编辑:程序博客网 时间:2024/04/27 04:16
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]; } }
阅读全文
1 0
- iOS中获取相册、相机、定位、以及麦克风权限设置
- ios获取相机,相册,麦克风权限
- iOS相机 相册 麦克风 定位等权限是否拥有
- iOS相册权限、相机权限、麦克风权限
- iOS相册权限、相机权限、麦克风权限
- iOS获取系统相册、相机、麦克风权限的工具
- iOS 10诸如相机、相册、通讯录、麦克风、定位权限设置,防止奔溃或上架被拒
- ios判断相册,相机,麦克风等权限
- iOS10获取相册/通讯录/相机/麦克风权限崩溃解决办法
- iOS 解决iOS10相册、相机、麦克风等权限使用问题
- iOS 相机权限以及相册权限访问
- xcode8调用 相册相机麦克风定位什么的
- iOS相册、相机、通讯录权限获取
- iOS相册、相机、通讯录权限获取
- iOS-相机,相册,位置访问权限设置
- 获取相册相机,定位
- iOS之访问(隐私)权限设置 通讯录、相册、麦克风等
- iOS 相机 麦克风 照片 权限的检测与获取
- Error: L6200E: Symbol SysTick_Handler multiply defined (by stm32f10x_it.o and m
- ANSI and UnicodeCharacter and String Data Types
- equals与==的区别
- Mysql中DATE_SUB 使用方法结合查询一天内,一周内,一月内的信息实例讲解
- 进制均值
- iOS中获取相册、相机、定位、以及麦克风权限设置
- Yii框架常用路径
- 点到任意直线的距离
- Redis集群搭建以及Spring整合
- AndroidStudio自定义包名
- Elasticsearch(二) 文档读写
- 软件停止后,相机状态为USE
- 马云怒怼阿尔法狗,称搞阿尔法狗没意义,人工智能的意义在哪?
- mysql建索引的几大原则