iOS 隐私授权 & 设置跳转

iOS用户隐私授权

  • 相机
    • Privacy - Camera Usage Description
  • 相册
    • 读权限 Privacy - Photo Library Usage Description
    • 写权限 Privacy - Photo Library Additions Usage Description
  • 麦克风
    • 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
  • 蓝牙 Privacy - Bluetooth Peripheral Usage Description
  • 本地网络 Privacy - Local Network Usage Description
  • 面容/指纹 Privacy - Face ID Usage Description
  • 运动与健身 Privacy - Motion Usage Description
  • 语音识别(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
    NSCameraUsageDescription            以便使用拍照功能获取图片设置用户头像以及发布动态等
    NSContactsUsageDescription          以便快速填写联系人信息
    NSLocationAlwaysUsageDescription    以便获取附近的人
    NSLocationWhenInUseUsageDescription 以便获取附近的人
    NSMicrophoneUsageDescription        以便在个人资料或者聊天中发送语音
    NSPhotoLibraryAddUsageDescription   以便你可以保存你喜欢的图片
    NSPhotoLibraryUsageDescription      用于选取相册中的图片设置用户头像以及发布动态等

注意:该方法只有在未询问过用户授权的情况下生效,也就是只能第一次询问的时候调用
如果第一次调用时点击了不允许,再次监测状态时调用无效,只能提示用户去设置中打开开关。

麦克风 AVCaptureDevice

检测状态

    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
    switch (authStatus) {
        case AVAuthorizationStatusNotDetermined:
            //没有询问是否开启麦克风
            break;
        case AVAuthorizationStatusRestricted:
            //未授权,家长限制
            break;
        case AVAuthorizationStatusDenied:
            //未授权
            break;
        case AVAuthorizationStatusAuthorized:
            //已授权
            break;
        default:
            break;
    }

获取权限

    [AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) { }];

相机 AVCaptureDevice

检测状态

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    }

获取权限

    [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { }];

相册 PHPhotoLibrary

检测状态

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
        PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
        PHAuthorizationStatusNotDetermined = 0,
        PHAuthorizationStatusRestricted,
        PHAuthorizationStatusDenied,
        PHAuthorizationStatusAuthorized,
        PHAuthorizationStatusLimited API_AVAILABLE(ios(14)),
     } else {
         NSLog(@"相册不可用!");
     }

获取权限

    [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { }];

定位 CLLocationManager

#import
检测状态

    BOOL enable = [CLLocationManager locationServicesEnabled];//是否可用
    CLAuthorizationStatus state = [CLLocationManager authorizationStatus];//授权状态
    
    kCLAuthorizationStatusNotDetermined = 0,   // 用户未授权,即还未弹出OS的授权弹窗
    kCLAuthorizationStatusDenied,              // 用户拒绝定位权限,包括拒绝App或者全局开关关闭
    kCLAuthorizationStatusRestricted,          // 定位服务受限,该状态位用户无法通过设置页面进行改变
    kCLAuthorizationStatusAuthorizedAlways,    // 始终定位,即后台定位
    kCLAuthorizationStatusAuthorizedWhenInUse, // App使用的时候,允许定位
    kCLAuthorizationStatusAuthorized,          // iOS8.0之后已经被废弃

获取权限

    CLLocationManager *locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    [locationManager requestAlwaysAuthorization];
    [locationManager requestWhenInUseAuthorization];

通讯录 CNContactStore

#import
检测状态

    CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];
    
    CNAuthorizationStatusNotDetermined = 0, // 用户未授权,即还未弹出OS的授权弹窗
    CNAuthorizationStatusRestricted,        // 定位服务受限,该状态位用户无法通过设置页面进行改变
    CNAuthorizationStatusDenied,            // 用户拒绝定位权限,包括拒绝App或者全局开关关闭
    CNAuthorizationStatusAuthorized         // 已授权
    CNContactStore *contactStore = [[CNContactStore alloc] init];
    [contactStore requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) { }];

跳转到指定的系统设置 UIApplicationOpenSettingsURLString

prefs:root=在苹果审核中已经被列为私有API
prefs:root=bundleID 和 prefs:root=服务都不再支持,调用不会有任何反应!
苹果的要求是不可以再使用prefs:root以及App-Prefs:root的接口来做app内部和系统设置的跳转了。
现在做app系统设置跳转,官方的只能使用UIApplicationOpenSettingURLString.

    NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        if (@available(iOS 10.0, *)) {
            [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
            }];
        }
    }
2181638951200_.pic.jpg

你可能感兴趣的:(iOS 隐私授权 & 设置跳转)