一、權(quán)限匯總
隱私權(quán)限 |
版本 |
Infor.plist字段 |
定位服務(wù) |
* |
Privacy - Location Always Usage Description 、Privacy - Location When In Use Usage Description 沈善、Privacy - Location Always and When In Use Usage Description
|
通訊錄 |
* |
Privacy - Contacts Usage Description |
日歷 |
* |
Privacy - Calendars Usage Description |
提醒事項(xiàng) |
* |
Privacy - Reminders Usage Description |
相冊(cè)(讀權(quán)限) |
* |
Privacy - Photo Library Usage Description |
相冊(cè)(寫權(quán)限) |
* |
Privacy - Photo Library Additions Usage Description |
藍(lán)牙 |
* |
Privacy - Bluetooth Peripheral Usage Description |
麥克風(fēng) |
* |
Privacy - Microphone Usage Description |
相機(jī) |
* |
Privacy - Camera Usage Description |
本地網(wǎng)絡(luò) |
iOS14~ |
Privacy - Local Network Usage Description |
面容/指紋 |
* |
Privacy - Face ID Usage Description |
運(yùn)動(dòng)與健身 |
* |
Privacy - Motion Usage Description |
語音識(shí)別(Siri) |
iOS10~ |
Privacy - Siri Usage Description |
健康 |
iOS8 ~ |
Privacy - Health Share Usage Description 迹鹅、Privacy - Health Update Usage Description
|
Home kit |
iOS8 ~ |
Privacy - HomeKit Usage Description |
媒體與Apple Music |
iOS 9 ~ |
Privacy - Media Library Usage Description |
三、權(quán)限設(shè)置相關(guān)代碼匯總
- 定位服務(wù)
BOOL enable = [CLLocationManager locationServicesEnabled];//是否可用
NSInteger state = [CLLocationManager authorizationStatus];//授權(quán)狀態(tài)
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
[self.locationManager requestAlwaysAuthorization];
[self.locationManager requestWhenInUseAuthorization];
- 通訊錄
CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];
CNContactStore *contactStore = [[CNContactStore alloc] init];
[contactStore requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {}];
- 日歷
EKAuthorizationStatus status = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent];
EKEventStore *store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError * _Nullable error) {}];
- 提醒事項(xiàng)
EKAuthorizationStatus status = [EKEventStore authorizationStatusForEntityType:EKEntityTypeReminder];
EKEventStore *store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeReminder completion:^(BOOL granted, NSError * _Nullable error) {
}];
- 照片
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
if (_isiOS8_Or_Later_) {
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
} else {
// iOS7 - iOS8
ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];
}
} else {
NSLog(@"相冊(cè)不可用替蛉!");
}
if (_isiOS8_Or_Later_) {
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
}];
} else {
ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];
[assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
} failureBlock:^(NSError *error) {
}];
}
- 藍(lán)牙
self.cbCentralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
#pragma mark - CBCentralManagerDelegate
- (void)centralManagerDidUpdateState:(CBCentralManager *)central{
CBManagerState state = central.state;
}
}
- 麥克風(fēng)
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
[[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {}];
- 相機(jī)
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
}
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
}];
- 運(yùn)動(dòng)與健身
if( [CMMotionActivityManager isActivityAvailable]){
CMAuthorizationStatus status = [CMMotionActivityManager authorizationStatus];
}
self.cmManager = [[CMMotionActivityManager alloc] init];
self.motionActivityQueue = [[NSOperationQueue alloc] init];
[self.cmManager startActivityUpdatesToQueue:self.motionActivityQueue withHandler:^(CMMotionActivity *activity) {}];
- 語音識(shí)別
SFSpeechRecognizerAuthorizationStatus status = [SFSpeechRecognizer authorizationStatus];
[SFSpeechRecognizer requestAuthorization:^(SFSpeechRecognizerAuthorizationStatus status) {
}];
- 健康
if ([HKHealthStore isHealthDataAvailable]) {
self.healthStore = [[HKHealthStore alloc] init];
// 以心率 HKQuantityTypeIdentifierHeartRate 為例子
HKQuantityType *heartRateType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeartRate];
HKAuthorizationStatus status = [self.healthStore authorizationStatusForType:heartRateType];
}else{
NSLog(@"unavailable");
// Health data is not avaliable on all device.
}
[self.healthStore requestAuthorizationToShareTypes:typeSet readTypes:typeSet completion:^(BOOL success, NSError * _Nullable error) {}];
- Home Kit
self.homeManager = [[HMHomeManager alloc] init];
self.homeManager.delegate = self;
- (void)homeManagerDidUpdateHomes:(HMHomeManager *)manager{
if (manager.homes.count > 0) {}
}
[manager addHomeWithName:@"Test Home" completionHandler:^(HMHome * _Nullable home, NSError * _Nullable error) {}];
- 媒體與Apple Music
SKCloudServiceAuthorizationStatus status = [SKCloudServiceController authorizationStatus];
[SKCloudServiceController requestAuthorization:^(SKCloudServiceAuthorizationStatus status) {}];
- 面容、指紋
YZAuthID *authID = [[YZAuthID alloc] init];
[authID yz_showAuthIDWithDescribe:nil block:^(YZAuthIDState state, NSError *error) {
if (state == YZAuthIDStateNotSupport) { // 不支持TouchID/FaceID
NSLog(@"對(duì)不起拄氯,當(dāng)前設(shè)備不支持指紋/面容ID");
} else if(state == YZAuthIDStateFail) { // 認(rèn)證失敗
NSLog(@"指紋/面容ID不正確躲查,認(rèn)證失敗");
} else if(state == YZAuthIDStateTouchIDLockout) { // 多次錯(cuò)誤,已被鎖定
NSLog(@"多次錯(cuò)誤译柏,指紋/面容ID已被鎖定镣煮,請(qǐng)到手機(jī)解鎖界面輸入密碼");
} else if (state == YZAuthIDStateSuccess) { // TouchID/FaceID驗(yàn)證成功
NSLog(@"認(rèn)證成功!");
}
}];