升到iOS10之后,需要设置权限的有:
1、在Info.plist 需要添加
麦克风权限: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
2、源码
//
// PrivacyAuthUtil.h
// TeamTalk
//
// Created by 程锦秀 on 16/12/10.
// Copyright © 2016年 MoguIM. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface PrivacyAuthUtil : NSObject
//单例
+(instancetype)instance;
//是否启用麦克风
-(BOOL)isAuthMicrophone;
//是否启用相册权限
-(BOOL)isCanUsePhotos;
//是否启用照相机
-(BOOL)isAuthCamera;
//是否开启定位权限
-(BOOL)isAuthLocation;
//是否开启通讯录权限
-(BOOL)isAuthContacts;
@end
#import "PrivacyAuthUtil.h"
#import <AVFoundation/AVFoundation.h>
#import <AMapLocationKit/AMapLocationKit.h>
#import <AssetsLibrary/AssetsLibrary.h>
#import <Photos/Photos.h>
@import AddressBook;
@implementation PrivacyAuthUtil
+(instancetype)instance
{
static PrivacyAuthUtil *privacy;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
if (privacy == nil) {
privacy = [[PrivacyAuthUtil alloc]init];
}
});
return privacy;
}
#pragma mark-是否启用麦克风权限
-(BOOL)isAuthMicrophone
{
AVAuthorizationStatus status = [AVCaptureDeviceauthorizationStatusForMediaType:AVMediaTypeAudio];
if (status == AVAuthorizationStatusRestricted ||status == AVAuthorizationStatusDenied
){
return NO;
}
return YES;
/*
[AVCaptureDevice requestAccessForMediaType:
AVMediaTypeAudio completionHandler:^(BOOL granted)
{
//麦克风权限
if (granted) {
NSLog(@"Authorized");
isOpen = YES;
}
else{
NSLog(@"Denied or Restricted");
isOpen = NO;
}
}];*/
}
#pragma mark -否有权限访问相册
-(BOOL)isCanUsePhotos {
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0) {
ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];
if (status == kCLAuthorizationStatusRestricted ||status == kCLAuthorizationStatusDenied
) {return NO;
}
}
else {
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
if (status == PHAuthorizationStatusRestricted ||
status == PHAuthorizationStatusDenied) {
return NO;
}
}
return YES;
}
#pragma mark -判断用户是否有权限访问相机
-(BOOL)isAuthCamera
{
AVAuthorizationStatus status = [AVCaptureDeviceauthorizationStatusForMediaType:AVMediaTypeVideo];
if (status == AVAuthorizationStatusRestricted ||status == AVAuthorizationStatusDenied
){
return NO;
}
return YES;
/*
[AVCaptureDevice requestAccessForMediaType:
AVMediaTypeVideo completionHandler:^(BOOL granted) {
if (granted) {
NSLog(@"Authorized");
}
else{
NSLog(@"Denied or Restricted");
}
}];
*/
}
#pragma mark -是否开启定位权限
-(BOOL)isAuthLocation
{
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
if (status == kCLAuthorizationStatusDenied || status == kCLAuthorizationStatusRestricted)
{
return NO;
/*
//读取本地数据
NSString * isPositioning = [[NSUserDefaults standardUserDefaults] valueForKey:@"isPositioning"];
if (isPositioning == nil)//提示
{
UIAlertView * positioningAlertivew = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"为了更好的体验,请到设置->隐私->定位服务中开启!【xxxAPP】定位服务,已便获取附近信息!" delegate:self cancelButtonTitle:@"确认" otherButtonTitles:@"永不提示",@"残忍拒绝",nil];
positioningAlertivew.tag = 30;
[positioningAlertivew show];
}*/
}
return YES;
}
#pragma mark -是否开启通讯录权限
-(BOOL)isAuthContacts
{
ABAuthorizationStatus status = ABAddressBookGetAuthorizationStatus();
if (status == kABAuthorizationStatusRestricted ||status == kABAuthorizationStatusDenied) {
return NO;
}
return YES;
/*
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
if (granted)
{
NSLog(@"Authorized");
CFRelease(addressBook);
}else{
NSLog(@"Denied or Restricted");
}
});
*/
}
@end