ios隐私权限的使用及设置

news/2024/11/17 20:39:31/

iOS隐私权限类别如下:

麦克风权限: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
网络权限:App Transport Security Settings — Allow Arbitrary Loads

常用的几种权限设置

一、相机权限:
判断是否已开启相机权限yes是开启:

- (BOOL)requestCaptureDeviceAuthor {AVAuthorizationStatus authStatus =[AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];if (authStatus == AVAuthorizationStatusDenied ||authStatus == AVAuthorizationStatusRestricted ||authStatus == AVAuthorizationStatusNotDetermined) {return NO;}return YES;
}

判断是否已询问相机权限:
authStatus==AVAuthorizationStatusNotDetermined时表示为询问相机权限,需要系统弹框提示开启或拒绝:调用requestAccessForMediaType方法就会掉漆系统弹框询问,如下代码:

AVAuthorizationStatus authStatus =[AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (authStatus == AVAuthorizationStatusNotDetermined) {// 回调函数在任意队列,包括分线程。[AVCaptureDevicerequestAccessForMediaType:AVMediaTypeVideocompletionHandler:^(BOOL granted) {dispatch_async(dispatch_get_main_queue(), ^{if (granted) {// 再次判断用户是否同意授权authorityPermisstion =[self requestCaptureDeviceAuthor];进行跳转或其他操作。}});}];return;
}

二、相册权限:
判断是否已开启相册权限yes是开启:

#import <Photos/Photos.h>
- (BOOL)photoAuthority {PHAuthorizationStatus photoAuthStatus = [PHPhotoLibrary authorizationStatus];if (photoAuthStatus ==PHAuthorizationStatusNotDetermined) {  // 未询问是否授权 可以用下面的请求授权方法询问用户return NO;} else if (photoAuthStatus == PHAuthorizationStatusRestricted ||photoAuthStatus == PHAuthorizationStatusDenied) {  // 未授权return NO;}// 已授权return YES;
}

当PHAuthorizationStatus == PHAuthorizationStatusNotDetermined代表权限未询问,需要调用PHPhotoLibrary requestAuthorization方法进行弹框询问:

PHAuthorizationStatus oldStatus = [PHPhotoLibrary authorizationStatus];
if (oldStatus == PHAuthorizationStatusNotDetermined) {[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {dispatch_async(dispatch_get_main_queue(), ^{if (status != PHAuthorizationStatusNotDetermined) {// 再次判断相册当前权限状态是否已开启authorityPermisstion = [self photoAuthority];进行其他操作}});}];
}

三、通讯录权限
判断是否已开启通讯录权限yes是开启:

#import <Contacts/Contacts.h>
#import <ContactsUI/ContactsUI.h>
- (BOOL)addressBookAuthority {if ([CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts] != CNAuthorizationStatusAuthorized) {return NO;}return YES;
}

当[CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts] ==CNAuthorizationStatusNotDetermined时表示权限未询问,通过调用requestAccessForEntityType来进行弹框询问,如下代码:

   if ([CNContactStoreauthorizationStatusForEntityType:CNEntityTypeContacts] ==CNAuthorizationStatusNotDetermined) {// 未询问CNContactStore* contactStore = [[CNContactStore alloc] init];[contactStorerequestAccessForEntityType:CNEntityTypeContactscompletionHandler:^(BOOL granted, NSError* _Nullable error) {[ISTools performCodeAtMainTheard:^{if (granted) {// 再次判断是否已开启通讯录权限authorityPermisstion = [self addressBookAuthority];进行其他操作}}];}];}

四、麦克风权限
判断麦克风权限是否已开启

#import <AVFoundation/AVFoundation.h>
- (BOOL)audioAuthority {BOOL state = YES;AVAuthorizationStatus authStatus =[AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];switch (authStatus) {case AVAuthorizationStatusNotDetermined: {  // 没有询问是否开启麦克风state = NO;} break;case AVAuthorizationStatusRestricted: {  // 未授权,家长限制state = NO;} break;case AVAuthorizationStatusDenied: {  // 玩家未授权 提示:“亲,麦克风权限已关闭,请在系统“设置”-“隐私”-“麦克风”-“热门直播”里开启”state = NO;} break;case AVAuthorizationStatusAuthorized: {  // 玩家授权state = YES;} break;}return state;
}

当authStatus == AVAuthorizationStatusNotDetermined时,代表权限从未询问过,需调用requestAccessForMediaType方法进行弹框询问,如下代码:

AVAuthorizationStatus authStatus =[AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
if (authStatus == AVAuthorizationStatusNotDetermined) {[AVCaptureDevicerequestAccessForMediaType:AVMediaTypeAudiocompletionHandler:^(BOOL granted) {dispatch_async(dispatch_get_main_queue(), ^{if (granted) {// 用户同意授权authorityPermisstion = [self audioAuthority];进行其他操作}});}];
}

五、地理位置权限
判断是否已开启地理位置使用权限,yes已允许使用位置:

#import <CoreLocation/CoreLocation.h>
- (BOOL)isOpenLocation {if ([CLLocationManager locationServicesEnabled] &&([CLLocationManager authorizationStatus] ==kCLAuthorizationStatusAuthorizedAlways ||[CLLocationManager authorizationStatus] ==kCLAuthorizationStatusAuthorizedWhenInUse)) {return YES;} else {return NO;}
}

当[CLLocationManager locationServicesEnabled] &&CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined时代表从未询问过位置权限,需requestWhenInUseAuthorization方法进行弹框询问,如下代码:

if ([CLLocationManager locationServicesEnabled] &&[CLLocationManager authorizationStatus] ==kCLAuthorizationStatusNotDetermined) {if (!self.locManager) {self.locManager = [[CLLocationManager alloc] init];self.locManager.delegate = self;}[self.locManager requestWhenInUseAuthorization];return;
}

弹框询问是否开启使用位置后,通过CLLocationManagerdelegate方法-- (void)locationManager:(CLLocationManager*)manager
didChangeAuthorizationStatus:(CLAuthorizationStatus)status进行回调得知询问的结果status。

#pragma mark--CLLocationManagerdelegate
- (void)locationManager:(CLLocationManager*)managerdidChangeAuthorizationStatus:(CLAuthorizationStatus)status {if (status == kCLAuthorizationStatusAuthorizedAlways ||status == kCLAuthorizationStatusAuthorizedWhenInUse) {
//   [self pushAuthoritySetViewControllerWithTitle:@"地理位置"
//                              authorityDescString:
//                                  @"若您授权地理位置权限,该权限将用于发现附近"
//                                  @"的直播内容,当您开播时也会推荐给附近的人观"
//                                  @"看,建议您允许以保证体验的流畅"
//                             authorityPermisstion:[self isOpenLocation]];  }
}

http://www.ppmy.cn/news/749986.html

相关文章

ios 设置权限

<key>NSAppleMusicUsageDescription</key> <string>App需要您的同意,才能访问媒体资料库</string> <key>NSBluetoothPeripheralUsageDescription</key> <string>App需要您的同意,才能访问蓝牙</string> <key>NSCale…

iOS 网络权限管理

网络权限管理 一、iOS网络情况分类&#xff1a; 通过App应用设置网络使用权限&#xff08;关闭、WLAN、WLAN与蜂窝移动网&#xff09;直接设置手机网络情况&#xff08;飞行模式、无线局域网络、蜂窝移动网络&#xff09; 二、iOS开发使用到的网络判断类&#xff1a; AFNetw…

iOS 全部访问权限设置

plist文件里面添加&#xff0c;Privacy - Photo Library Usage Description&#xff0c;Value值为描述&#xff0c;弹出的提示框会显示出来。 升到iOS10之后&#xff0c;需要设置权限的有&#xff1a; 麦克风权限&#xff1a;Privacy - Microphone Usage Description 是否允许…

iOS 访问权限设置

iOS 10 以后 NSAppleMusicUsageDescription App需要您的同意,才能访问媒体资料库 NSBluetoothPeripheralUsageDescription App需要您的同意,才能访问蓝牙 NSCalendarsUsageDescription App需要您的同意,才能访问日历 NSCameraUsageDescription App需要您的同意,才能访问相…

iOS权限设置

iOS开发指南&#xff1a; https://www.developboot.com/blog/ 苹果要求权限详细&#xff1a;美图的&#xff1a;使用您的位置来获取您附近的团购信息 麦克风权限: Privacy - Microphone Usage Description 是否允许此App使用您的麦克风&#xff1f; 相册权限: Privacy - Photo …

力扣 78. 子集

题目来源&#xff1a;https://leetcode.cn/problems/subsets/description/ C题解1&#xff1a;递归回溯法。由于是求子集&#xff0c;所以根据nums.size()遍历每个子集的长度&#xff0c;并进行回溯。 class Solution { public:vector<vector<int>> res;vector<…

7.6机试练习

1. 2105 IP Address 描述 Suppose you are reading byte streams from any device, representing IP addresses. Your task is to convert a 32 characters long sequence of ‘1s’ and ‘0s’ (bits) to a dotted decimal format. A dotted decimal format for an IP addres…

车灯线光源的优化设计matlab,车灯线光源的优化设计

车灯线光源的优化设计摘要本题主要以车灯线光源的优化设计为研究对象&#xff0c;在研究过程中建立了线性规化模型&#xff0c;给出算法并利用MATLAB软件求解。针对问题一&#xff0c;首先将线光源长度及其折射面离散化处理&#xff0c;将线光源的散射问题转换为光线间的折射问…