#import
//获取相册授权状态
- (void) checkPhotoStauts{
PHAuthorizationStatus photoAuthorStatus = [PHPhotoLibrary authorizationStatus];
switch(photoAuthorStatus) {
case PHAuthorizationStatusAuthorized:
NSLog(@"用户已授权");
break;
case PHAuthorizationStatusDenied:
NSLog(@"用户已拒绝");
break;
case PHAuthorizationStatusNotDetermined:
NSLog(@"用户还未进行选择");
break;
case PHAuthorizationStatusRestricted:
NSLog(@"客户端未被授权访问媒体类型的硬件。用户不能改变客户端的状态,可能是由于诸如父母控制的活动限制发生");
break;
default:
break;
}
}
//授权相册
- (void)photoAction{
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
switch(status) {
case PHAuthorizationStatusAuthorized:
NSLog(@"用户已授权");
break;
case PHAuthorizationStatusDenied:
NSLog(@"用户已拒绝");
break;
case PHAuthorizationStatusNotDetermined:
NSLog(@"用户还未进行选择");
break;
case PHAuthorizationStatusRestricted:
NSLog(@"客户端未被授权访问媒体类型的硬件。用户不能改变客户端的状态,可能是由于诸如父母控制的活动限制发生");
break;
default:
break;
}
}];
}
#import
//获取录制视频授权状态
- (void) checkVideoStatus {
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
switch(authStatus) {
case AVAuthorizationStatusNotDetermined:
NSLog(@"用户还未进行选择");
break;
case AVAuthorizationStatusRestricted:
NSLog(@"客户端未被授权访问媒体类型的硬件。用户不能改变客户端的状态,可能是由于诸如父母控制的活动限制发生");
break;
case AVAuthorizationStatusDenied:
NSLog(@"用户已拒绝");
break;
case AVAuthorizationStatusAuthorized:
NSLog(@"用户已授权");
break;
default:
break;
}
}
- (void)videoStatusAlert {
//调用该方法,系统会自动弹框让用户选择相机是否授权
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if (granted) {
NSLog(@"用户授权");
}else{
NSLog(@"用户拒绝");
}
}];
}
#import
//获取录音授权状态
- (void)getRecordStatus {
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
switch(authStatus) {
case AVAuthorizationStatusNotDetermined:
NSLog(@"用户还未进行选择");
break;
case AVAuthorizationStatusRestricted:
NSLog(@"客户端未被授权访问媒体类型的硬件。用户不能改变客户端的状态,可能是由于诸如父母控制的活动限制发生");
break;
case AVAuthorizationStatusDenied:
NSLog(@"用户已拒绝");
break;
case AVAuthorizationStatusAuthorized:
NSLog(@"用户已授权");
break;
default:
break;
}
}
- (void)recordStatusAlert {
//调用该方法,系统会自动弹框让用户选择麦克风是否授权
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) {
if (granted) {
NSLog(@"用户授权");
}else{
NSLog(@"用户拒绝");
}
}];
}
#import
//定位权限
- (void)getLocationStauts {
CLAuthorizationStatus locationStatus = [CLLocationManager authorizationStatus];
switch(locationStatus) {
case kCLAuthorizationStatusNotDetermined:
NSLog(@"用户还未进行选择");
break;
case kCLAuthorizationStatusRestricted:
NSLog(@"客户端未被授权访问媒体类型的硬件。用户不能改变客户端的状态,可能是由于诸如父母控制的活动限制发生");
break;
case kCLAuthorizationStatusDenied:
NSLog(@"用户已拒绝");
break;
case kCLAuthorizationStatusAuthorizedAlways:
NSLog(@"用户已授权允许一直获取定位");
break;
case kCLAuthorizationStatusAuthorizedWhenInUse:
NSLog(@"用户已授权允许app使用期间获取定位");
break;
//kCLAuthorizationStatusAuthorized iOS8.0弃用
// case kCLAuthorizationStatusAuthorized:
// NSLog(@"用户已授权获取定位");
// break;
default:
break;
}
}
- (void)locationAction {
//获取app使用期间定位授权
[[[CLLocationManager alloc]init] requestWhenInUseAuthorization];
//获取app一直定位授权
[[[CLLocationManager alloc]init] requestAlwaysAuthorization];
}
#import
//通讯录
- (void)bookStatus {
CNAuthorizationStatus bookStatus = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];
switch(bookStatus) {
case CNAuthorizationStatusAuthorized:
NSLog(@"用户已授权");
break;
case CNAuthorizationStatusDenied:
NSLog(@"用户已拒绝");
break;
case CNAuthorizationStatusNotDetermined:
NSLog(@"用户还未进行选择");
break;
case CNAuthorizationStatusRestricted:
NSLog(@"客户端未被授权访问媒体类型的硬件。用户不能改变客户端的状态,可能是由于诸如父母控制的活动限制发生");
break;
default:
break;
}
}
- (void)getBookAction {
CNContactStore *store = [[CNContactStore alloc]init];
[storerequestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {
if(granted) {
NSLog(@"用户授权");
}else{
NSLog(@"用户拒绝");
}
}];
}
#import
//在日历中添加提醒事件
- (void)calendarStatus {
EKAuthorizationStatus eventStatus = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent];
switch(eventStatus) {
case EKAuthorizationStatusAuthorized:
NSLog(@"用户已授权");
break;
case EKAuthorizationStatusDenied:
NSLog(@"用户已拒绝");
break;
case EKAuthorizationStatusNotDetermined:
NSLog(@"用户还未进行选择");
break;
case EKAuthorizationStatusRestricted:
NSLog(@"客户端未被授权访问媒体类型的硬件。用户不能改变客户端的状态,可能是由于诸如父母控制的活动限制发生");
break;
default:
break;
}
}
- (void)getCalendarAction {
EKEventStore *store = [[EKEventStore alloc]init];
[storerequestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError * _Nullable error) {
if(granted) {
NSLog(@"用户授权");
}else{
NSLog(@"用户拒绝");
}
}];
}
#import
//在提醒事项中添加提醒事件
- (void)rememberStatus {
EKAuthorizationStatus eventStatus = [EKEventStore authorizationStatusForEntityType:EKEntityTypeReminder];
switch(eventStatus) {
case EKAuthorizationStatusAuthorized:
NSLog(@"用户已授权");
break;
case EKAuthorizationStatusDenied:
NSLog(@"用户已拒绝");
break;
case EKAuthorizationStatusNotDetermined:
NSLog(@"用户还未进行选择");
break;
case EKAuthorizationStatusRestricted:
NSLog(@"客户端未被授权访问媒体类型的硬件。用户不能改变客户端的状态,可能是由于诸如父母控制的活动限制发生");
break;
default:
break;
}
}
- (void)getRememberAction {
EKEventStore *store = [[EKEventStore alloc]init];
[storerequestAccessToEntityType:EKEntityTypeReminder completion:^(BOOL granted, NSError * _Nullable error) {
if(granted) {
NSLog(@"用户授权");
}else{
NSLog(@"用户拒绝");
}
}];
}
#import
@interface ViewController ()
@property (nonatomic, strong) CBCentralManager *manager;
@end
@implementation ViewController
- (void)blueToothStatus {
//CBCentralManagerDelegate 实时监控蓝牙状态
//CBCentralManager会在传入的queue线程队列调用,如果queue为nil则在主线程队列调用。
//CBCentralManager的创建为异步,如果初始化完成之后没有被当前类持有,就会被释放掉。如果CBCentralManager实例不是在当前类中创建的,那么持有CBCentralManager的这个类在初始化之后也必须被当前类持有,否则控制台会输出错误:[CoreBluetooth] XPC connection invalid
//CBCentralManager声明成功后,会调用centralManagerDidUpdateState:代理方法
//当manager声明后若为授权,则系统会弹框引导用户前往设置蓝牙页面
self.manager = [[CBCentralManager alloc]initWithDelegate:self queue:nil];
}
- (void)centralManagerDidUpdateState:(CBCentralManager*)central {
switch(central.state) {
case CBManagerStateUnknown:
NSLog(@"未知状态(刚刚创建的时候)");
break;
case CBManagerStateResetting:
NSLog(@"正在重置状态");
break;
case CBManagerStateUnsupported:
NSLog(@"设备不支持的状态");
break;
case CBManagerStateUnauthorized:
NSLog(@"设备未授权状态");
break;
case CBManagerStatePoweredOff:
NSLog(@"设备关闭状态");
break;
case CBManagerStatePoweredOn:
NSLog(@"设备开启状态 -- 可用状态");
break;
default:
break;
}
}
@end
在info中需要添加的授权内容:
Privacy - AppleEvents Sending Usage Description Apple事件发送权限
Privacy - Bluetooth Peripheral Usage Description 蓝牙权限
Privacy - Calendars Usage Description 日历权限
Privacy - Camera Usage Description 摄像头权限
Privacy - Contacts Usage Description 通讯录权限
Privacy - Face ID Usage Description faceID权限
Privacy - Health Records Usage Description 读取健康数据权限
Privacy - Health Share Usage Description 健康分享权限
Privacy - Health Update Usage Description 健康数据更新权限
Privacy - HomeKit Usage Description HomeKit权限
Privacy - Location Always and When In Use Usage Description 一直定位包括app使用期间权限
Privacy - Location Always Usage Description 一直定位权限
Privacy - Location Usage Description 定位权限
Privacy - Location When In Use Usage Description app使用期间定位权限
Privacy - Media Library Usage Description 媒体资料权限
Privacy - Microphone Usage Description 麦克风权限
Privacy - Motion Usage Description 运动与健身权限
Privacy - Music Usage Description 音乐库添加权限
Privacy - NFC Scan Usage Description NFC 扫描权限
Privacy - Photo Library Additions Usage Description 相册添加权限
Privacy - Photo Library Usage Description 照片库使用权限
Privacy - Reminders Usage Description 在提醒事件中添加事件的权限
Privacy - Siri Usage Description siri权限
Privacy - Speech Recognition Usage Description 语音识别权限
Privacy - System Administration Usage Description 系统管理权限
Privacy - TV Provider Usage Description TV权限
未完。。。。