iOS授权合集 DHAuthorizationManager

DHAuthorizationManager

iOS授权集合,可同时请求多授权

支持授权

  • Camera: 相机
  • Microphone: 麦克风
  • PhoneLibrary: 相册
  • Contact: 通讯录
  • Calendar: 日历
  • Reminder: 提醒
  • LocationWhenInUse: 试用期间的定位
  • LocationAlways: 始终使用的定位
  • AppleMusic: 媒体库
  • SpeechRecognition: 语音识别
  • Siri
  • Motion: 运动
  • HealthUpdate: 健康更新
  • HealthShare: 健康分享
  • UserNotification: 本地推送
  • BluetoothPeripheral: 蓝牙
  • Cellular: 蜂窝数据

你需要知道的!

注意

  • AppleMusic: 必须用真机测试,不然方法无响应,可能引起内存泄漏
  • HealthUpdate/HealthShare: 必须提供NSSet<HKOjbectType/HKSampleType*>*参数
  • UserNotification: 必须提供@(UNAuthorizationOptions)参数
  • Siri: 需要打开项目->TARGET->Capabilities->Siri

已知Bug——如果你有很好的解决办法,请告知我,谢谢

  • UserNotification: 始终反馈已授权,其中的-requestAccess也没反应

  • Cellular: 一直得不到正确状态

  • BluetoothPeripheral: 得不到正确状态

安装

pod 'DHAuthorizationManager'
  • 当前版本:1.0.0

使用方法

1. 引用头文件并设置为强引用属性

  • 设置为属性,授权弹框才能正常显示
#import "DHAuthorizationManager.h"

@property (nonatomic, strong) DHAuthorizationManager *authorizationManager;

2. 初始化

self.authorizationManager = [[DHAuthorizationManager alloc] init];
self.authorizationManager.delegate = self;

3. 请求授权

[self.authorizationManager checkAuthorizationForKey:DHAuthorizationKeyCamera|DHAuthorizationMicrophone withParameters:nil completion:^(NSDictionary <NSNumber *, NSNumber *> *_Nonnull result) {
  // 授权结果result <@(DHAuthorizationKey), @(DHAuthorizationStatus)>
  // do something...
}];

>> or
[self.authorizationManager checkAuthorizationForKey:DHAuthorizationKeyCamera|DHAuthorizationMicrophone withParameters:nil];
/** 授权结果result <@(DHAuthorizationKey), @(DHAuthorizationStatus)> */
- (void)authorizationResult:(NSDictionary <NSNumber *, NSNumber *> *)result {
  // do something...
}

DHAuthorizationStatus说明

  • DHAuthorizationStatusDefault: 默认
  • DHAuthorizationStatusNotDetermined: 未决定。未曾请求过授权,此时会尝试请求授权
  • DHAuthorizationStatusAuthorized: 已授权
  • DHAuthorizationStatusNotConfigured: 未配置。info.plist文件未设置相应的键值,用于编码时测试
  • DHAuthorizationStatusDenied: 已拒绝。用户已拒绝授权
  • DHAuthorizationStatusRestricted: 受限制
  • DHAuthorizationStatusNotSupported: 系统版本或硬件不支持
  • DHAuthorizationStatusSystemSetting: 未提供授权方法,建议跳转至系统进行设置

DHAuthorizationDemo

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值