Coder Social home page Coder Social logo

danielhusx / dhauthorizationmanager Goto Github PK

View Code? Open in Web Editor NEW
2.0 0.0 0.0 139 KB

集合iOS权限请求,可多个权限同时请求

License: MIT License

Objective-C 95.83% Ruby 4.17%
ios-authorization authorization siri camera micripohone usernotification healthshare

dhauthorizationmanager's Introduction

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,不然点击必崩

安装

pod 'DHAuthorizationManager'
  • 当前版本:1.0.1

使用方法

注意:必须将DHAuthorizationManager设置为强引用成员属性,授权弹框才能正常显示

方法一:使用Block

#import "DHAuthorizationManager.h"
// 强引用
@property (nonatomic, strong) DHAuthorizationManager *authorizationManager;
// 初始化
self.authorizationManager = [[DHAuthorizationManager alloc] init];
// 请求权限校验
DHAuthorizationKey key = DHAuthorizationKeyCamera|DHAuthorizationKeyMicrophone;
[self.authorizationManager checkAuthorizationForKey:key withParameters:nil completion:^(NSDictionary <NSNumber *, NSNumber *> *_Nonnull result) {
  // 授权结果result <@(DHAuthorizationKey), @(DHAuthorizationStatus)>
  // do something...
}];

方法二:使用代理

#import "DHAuthorizationManager.h"
// 强引用
@property (nonatomic, strong) DHAuthorizationManager *authorizationManager;
// 初始化
self.authorizationManager = [[DHAuthorizationManager alloc] init];
self.authorizationManager.delegate = self;

// 请求权限校验
DHAuthorizationKey key = DHAuthorizationKeyCamera|DHAuthorizationKeyMicrophone;
[self.authorizationManager checkAuthorizationForKey:key withParameters:nil];

/** 代理反馈授权结果result <@(DHAuthorizationKey), @(DHAuthorizationStatus)> */
- (void)authorizationResult:(NSDictionary <NSNumber *, NSNumber *> *)result {
  // do something...
}

DHAuthorizationStatus说明

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

dhauthorizationmanager's People

Contributors

danielhusx avatar

Stargazers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.