iOS用戶隱私授權(quán)
- 相機(jī)
- Privacy - Camera Usage Description
- 相冊(cè)
- 讀權(quán)限 Privacy - Photo Library Usage Description
- 寫(xiě)權(quán)限 Privacy - Photo Library Additions Usage Description
- 麥克風(fēng)
- Privacy - Microphone Usage Description
- 定位
- Privacy - Location Always Usage Description
- Privacy - Location When In Use Usage Description
- 通訊錄
- Privacy - Contacts Usage Description
- 通訊錄 Privacy - Contacts Usage Description
- 日歷 Privacy - Calendars Usage Description
- 藍(lán)牙 Privacy - Bluetooth Peripheral Usage Description
- 本地網(wǎng)絡(luò) Privacy - Local Network Usage Description
- 面容/指紋 Privacy - Face ID Usage Description
- 運(yùn)動(dòng)與健身 Privacy - Motion Usage Description
- 語(yǔ)音識(shí)別(Siri) Privacy - Siri Usage Description
- 健康 Privacy - Health Share Usage Description 儒飒、Privacy - Health Update Usage Description
- Home kit Privacy - HomeKit Usage Description
- 媒體與Apple Music Privacy - Media Library Usage Description
<key>NSCameraUsageDescription</key> <string>以便使用拍照功能獲取圖片設(shè)置用戶頭像以及發(fā)布動(dòng)態(tài)等</string>
<key>NSContactsUsageDescription</key> <string>以便快速填寫(xiě)聯(lián)系人信息</string>
<key>NSLocationAlwaysUsageDescription</key> <string>以便獲取附近的人</string>
<key>NSLocationWhenInUseUsageDescription</key> <string>以便獲取附近的人</string>
<key>NSMicrophoneUsageDescription</key> <string>以便在個(gè)人資料或者聊天中發(fā)送語(yǔ)音</string>
<key>NSPhotoLibraryAddUsageDescription</key> <string>以便你可以保存你喜歡的圖片</string>
<key>NSPhotoLibraryUsageDescription</key> <string>用于選取相冊(cè)中的圖片設(shè)置用戶頭像以及發(fā)布動(dòng)態(tài)等</string>
注意:該方法只有在未詢問(wèn)過(guò)用戶授權(quán)的情況下生效,也就是只能第一次詢問(wèn)的時(shí)候調(diào)用
如果第一次調(diào)用時(shí)點(diǎn)擊了不允許鳍寂,再次監(jiān)測(cè)狀態(tài)時(shí)調(diào)用無(wú)效,只能提示用戶去設(shè)置中打開(kāi)開(kāi)關(guān)惭笑。
麥克風(fēng) AVCaptureDevice
檢測(cè)狀態(tài)
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
switch (authStatus) {
case AVAuthorizationStatusNotDetermined:
//沒(méi)有詢問(wèn)是否開(kāi)啟麥克風(fēng)
break;
case AVAuthorizationStatusRestricted:
//未授權(quán)戏阅,家長(zhǎng)限制
break;
case AVAuthorizationStatusDenied:
//未授權(quán)
break;
case AVAuthorizationStatusAuthorized:
//已授權(quán)
break;
default:
break;
}
獲取權(quán)限
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) { }];
相機(jī) AVCaptureDevice
檢測(cè)狀態(tài)
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
}
獲取權(quán)限
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { }];
相冊(cè) PHPhotoLibrary
檢測(cè)狀態(tài)
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
PHAuthorizationStatusNotDetermined = 0,
PHAuthorizationStatusRestricted,
PHAuthorizationStatusDenied,
PHAuthorizationStatusAuthorized,
PHAuthorizationStatusLimited API_AVAILABLE(ios(14)),
} else {
NSLog(@"相冊(cè)不可用!");
}
獲取權(quán)限
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { }];
定位 CLLocationManager
#import <CoreLocation/CoreLocation.h>
檢測(cè)狀態(tài)
BOOL enable = [CLLocationManager locationServicesEnabled];//是否可用
CLAuthorizationStatus state = [CLLocationManager authorizationStatus];//授權(quán)狀態(tài)
kCLAuthorizationStatusNotDetermined = 0, // 用戶未授權(quán)属瓣,即還未彈出OS的授權(quán)彈窗
kCLAuthorizationStatusDenied, // 用戶拒絕定位權(quán)限组民,包括拒絕App或者全局開(kāi)關(guān)關(guān)閉
kCLAuthorizationStatusRestricted, // 定位服務(wù)受限棒仍,該狀態(tài)位用戶無(wú)法通過(guò)設(shè)置頁(yè)面進(jìn)行改變
kCLAuthorizationStatusAuthorizedAlways, // 始終定位,即后臺(tái)定位
kCLAuthorizationStatusAuthorizedWhenInUse, // App使用的時(shí)候臭胜,允許定位
kCLAuthorizationStatusAuthorized, // iOS8.0之后已經(jīng)被廢棄
獲取權(quán)限
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager requestAlwaysAuthorization];
[locationManager requestWhenInUseAuthorization];
通訊錄 CNContactStore
#import <Contacts/CNContactStore.h>
檢測(cè)狀態(tài)
CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];
CNAuthorizationStatusNotDetermined = 0, // 用戶未授權(quán)莫其,即還未彈出OS的授權(quán)彈窗
CNAuthorizationStatusRestricted, // 定位服務(wù)受限,該狀態(tài)位用戶無(wú)法通過(guò)設(shè)置頁(yè)面進(jìn)行改變
CNAuthorizationStatusDenied, // 用戶拒絕定位權(quán)限耸三,包括拒絕App或者全局開(kāi)關(guān)關(guān)閉
CNAuthorizationStatusAuthorized // 已授權(quán)
CNContactStore *contactStore = [[CNContactStore alloc] init];
[contactStore requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) { }];
跳轉(zhuǎn)到指定的系統(tǒng)設(shè)置 UIApplicationOpenSettingsURLString
prefs:root=在蘋(píng)果審核中已經(jīng)被列為私有API
prefs:root=bundleID 和 prefs:root=服務(wù)都不再支持乱陡,調(diào)用不會(huì)有任何反應(yīng)!
蘋(píng)果的要求是不可以再使用prefs:root以及App-Prefs:root的接口來(lái)做app內(nèi)部和系統(tǒng)設(shè)置的跳轉(zhuǎn)了仪壮。
現(xiàn)在做app系統(tǒng)設(shè)置跳轉(zhuǎn)憨颠,官方的只能使用UIApplicationOpenSettingURLString.
NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
if (@available(iOS 10.0, *)) {
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
}];
}
}