iOS10
以后,需要在plist
文件里面添加各种权限:
升到iOS10之后,需要设置权限的有:
麦克风权限:Privacy - Microphone Usage Description 是否允许此App使用你的麦克风?
相机权限: Privacy - Camera Usage Description 是否允许此App使用你的相机?
相册权限: Privacy - Photo Library Usage Description 是否允许此App访问你的媒体资料库?
通讯录权限: Privacy - Contacts Usage Description 是否允许此App访问你的通讯录?
蓝牙权限:Privacy - Bluetooth Peripheral Usage Description 是否许允此App使用蓝牙?
语音转文字权限:Privacy - Speech Recognition Usage Description 是否允许此App使用语音识别?
日历权限:Privacy - Calendars Usage Description
定位权限:Privacy - Location When In Use Usage Description
定位权限: Privacy - Location Always Usage Description
位置权限:Privacy - Location Usage Description
媒体库权限:Privacy - Media Library Usage Description
健康分享权限:Privacy - Health Share Usage Description
健康更新权限:Privacy - Health Update Usage Description
运动使用权限:Privacy - Motion Usage Description
音乐权限:Privacy - Music Usage Description
提醒使用权限:Privacy - Reminders Usage Description
Siri使用权限:Privacy - Siri Usage Description
电视供应商使用权限:Privacy - TV Provider Usage Description
视频用户账号使用权限:Privacy - Video Subscriber Account Usage Description
1.麦克风权限
导入
#import <AVFoundation/AVFoundation.h>
//麦克风权限
AVAuthorizationStatus micStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
if (micStatus != AVAuthorizationStatusAuthorized) { // 麦克风权限没有开启
[self dealMicAuthWithStatus:micStatus];
}else {
NSLog(@"麦克风权限已经开启");
}
- (void)dealMicAuthWithStatus:(AVAuthorizationStatus)status {
switch (status) {
case AVAuthorizationStatusAuthorized:
NSLog(@"Authorized");//已授权
break;
case AVAuthorizationStatusDenied://拒绝
case AVAuthorizationStatusRestricted: { //家长限制
// 提示框提示
[self showAlertWithMessage:@"您已关闭麦克风权限,请前往设置打开"];
}
break;
case AVAuthorizationStatusNotDetermined: {
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) {
if (granted) {
NSLog(@"允许麦克风权限");
}else {
NSLog(@"拒绝麦克风权限");
}
}];
}
break;
default:
break;
}
}
#pragma mark - 提示框提示
- (void)showAlertWithMessage:(NSString *)message {
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"项目名称提示" message:message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if([[UIApplication sharedApplication] openURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
}];
[alertVC addAction:cancleAction];
[alertVC addAction:sureAction];
[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alertVC animated:YES completion:nil];
}


2.相机权限
//相机权限
AVAuthorizationStatus videoStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (videoStatus != AVAuthorizationStatusAuthorized) { // 相机权限没有开启
[self dealVideoAuthWithStatus:videoStatus];
}else {
NSLog(@"相机权限已经开启");
}
- (void)dealVideoAuthWithStatus:(AVAuthorizationStatus)status {
switch (status) {
case AVAuthorizationStatusAuthorized:
NSLog(@"Authorized");//已授权
break;
case AVAuthorizationStatusDenied://拒绝
case AVAuthorizationStatusRestricted: { //家长限制
// 提示框提示
[self showAlertWithMessage:@"您已关闭相机权限,请前往设置打开"];
}
break;
case AVAuthorizationStatusNotDetermined: {
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if (granted) {
NSLog(@"允许相机权限");
}else {
NSLog(@"拒绝相机权限");
}
}];
}
break;
default:
break;
}
}


3.相册权限
导入
#import <Photos/Photos.h>
// 相册权限
PHAuthorizationStatus photoStatus = [PHPhotoLibrary authorizationStatus];
if (photoStatus != PHAuthorizationStatusAuthorized) { // 相册权限没有开启
[self dealPhotoAuthWithStatus:photoStatus];
}else {
NSLog(@"相册权限已经开启");
}
- (void)dealPhotoAuthWithStatus:(PHAuthorizationStatus)status {
switch (status) {
case PHAuthorizationStatusAuthorized:
NSLog(@"Authorized");//已授权
break;
case PHAuthorizationStatusDenied://拒绝
case PHAuthorizationStatusRestricted: { //家长限制
// 提示框提示
[self showAlertWithMessage:@"您已关闭相册权限,请前往设置打开"];
}
break;
case PHAuthorizationStatusNotDetermined: {
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
if (status == PHAuthorizationStatusAuthorized) {
NSLog(@"相机权限开启");
}else {
NSLog(@"相机权限关闭");
}
}];
}
break;
default:
break;
}
}


网友评论