聯(lián)網(wǎng)權限晋南,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];