联网权限,CoreTelephony.framework框架下的CTCellularData类
CTCellularData *cellularData = [[CTCellularData alloc]init];
CTCellularDataRestrictedState state = cellularData.restrictedState;
switch (state) {
case kCTCellularDataRestrictedStateUnknown:
NSLog(@"未知");
break;
case kCTCellularDataRestricted:
NSLog(@"受限制,无权限");
break;
case kCTCellularDataNotRestricted:
NSLog(@"不被限制");
break;
}
CTCellularData *cellularData = [[CTCellularData alloc]init];
cellularData.cellularDataRestrictionDidUpdateNotifier = ^(CTCellularDataRestrictedState state){
switch (state) {
case kCTCellularDataRestrictedStateUnknown:
NSLog(@"未知");
break;
case kCTCellularDataRestricted:
NSLog(@"受限制,无权限");
break;
case kCTCellularDataNotRestricted:
NSLog(@"不被限制");
break;
};
};
相册权限,Photos.framework
PHAuthorizationStatus photoAuthorStatus = [PHPhotoLibrary authorizationStatus];
switch (photoAuthorStatus) {
case PHAuthorizationStatusNotDetermined:
NSLog(@"尚未授权");
break;
case PHAuthorizationStatusRestricted:
NSLog(@"受限制,无权限");
break;
case PHAuthorizationStatusDenied:
NSLog(@"用户拒绝授权");
break;
case PHAuthorizationStatusAuthorized:
NSLog(@"用户已授权");
break;
}
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
switch (status) {
case PHAuthorizationStatusNotDetermined:
NSLog(@"尚未授权");
break;
case PHAuthorizationStatusRestricted:
NSLog(@"受限制,无权限");
break;
case PHAuthorizationStatusDenied:
NSLog(@"用户拒绝授权");
break;
case PHAuthorizationStatusAuthorized:
NSLog(@"用户已授权");
break;
}
}];
相机权限,AVFoundation.framework
AVAuthorizationStatus AVstatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
switch (AVstatus) {
case AVAuthorizationStatusNotDetermined:
NSLog(@"尚未授权");
break;
case AVAuthorizationStatusRestricted:
NSLog(@"受限制,无权限");
break;
case AVAuthorizationStatusDenied:
NSLog(@"用户拒绝授权");
break;
case AVAuthorizationStatusAuthorized:
NSLog(@"用户已授权");
break;
}
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if (granted) {
NSLog(@"已授权");
} else {
NSLog(@"未授权");
}
}];
麦克风权限,AVFoundation.framework
AVAuthorizationStatus AVstatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];//麦克风权限
switch (AVstatus) {
case AVAuthorizationStatusNotDetermined:
NSLog(@"尚未授权");
break;
case AVAuthorizationStatusRestricted:
NSLog(@"受限制,无权限");
break;
case AVAuthorizationStatusDenied:
NSLog(@"用户拒绝授权");
break;
case AVAuthorizationStatusAuthorized:
NSLog(@"用户已授权");
break;
}
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) {
if (granted) {
NSLog(@"已授权");
} else {
NSLog(@"未授权");
}
}];
通讯录权限,Contacts.framework,AddressBook.framework
#ifdef __IPHONE_9_0
CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];
switch (status) {
case CNAuthorizationStatusNotDetermined:
NSLog(@"尚未授权");
break;
case CNAuthorizationStatusRestricted:
NSLog(@"受限制,无权限");
break;
case CNAuthorizationStatusDenied:
NSLog(@"用户拒绝授权");
break;
case CNAuthorizationStatusAuthorized:
NSLog(@"用户已授权");
break;
}
#else
ABAuthorizationStatus ABstatus = ABAddressBookGetAuthorizationStatus();
switch (ABstatus) {
case kABAuthorizationStatusNotDetermined:
NSLog(@"尚未授权");
break;
case kABAuthorizationStatusRestricted:
NSLog(@"受限制,无权限");
break;
case kABAuthorizationStatusDenied:
NSLog(@"用户拒绝授权");
break;
case kABAuthorizationStatusAuthorized:
NSLog(@"用户已授权");
break;
}
#endif
#ifdef __IPHONE_9_0
CNContactStore *contactStore = [[CNContactStore alloc] init];
[contactStore requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (granted) {
NSLog(@"已授权");
} else {
NSLog(@"未授权");
}
}];
#else
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
if (granted) {
NSLog(@"已授权");
} else {
NSLog(@"未授权");
}
});
#endif
定位权限,CoreLocation.framework
if ([CLLocationManager locationServicesEnabled]) {
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
switch (status) {
case kCLAuthorizationStatusNotDetermined:
NSLog(@"尚未授权");
break;
case kCLAuthorizationStatusRestricted:
NSLog(@"受限制,无权限");
break;
case kCLAuthorizationStatusDenied:
NSLog(@"用户拒绝授权");
break;
case kCLAuthorizationStatusAuthorizedAlways:
NSLog(@"用户已授权");
break;
case kCLAuthorizationStatusAuthorizedWhenInUse:
NSLog(@"用户已授权");
break;
default:
break;
}
}else {
NSLog(@"定位服务尚未开启");
}
CLLocationManager *locationManager = [[CLLocationManager alloc] init;
[locationManager requestAlwaysAuthorization];
// [locationManager requestWhenInUseAuthorization];