You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
179 lines
8.3 KiB
179 lines
8.3 KiB
2 years ago
|
JLAuthorizationManager
|
||
|
|
||
|
![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg) ![Pod Version](https://img.shields.io/badge/Pod-v2.0.2-orange.svg) ![Pod Platform](https://img.shields.io/badge/Platform-iOS-lightgrey.svg) ![System Version](https://img.shields.io/badge/iOS-8.0-blue.svg) [![Pod License](https://img.shields.io/badge/License-MIT-333333.svg)](https://www.apache.org/licenses/LICENSE-2.0.html)
|
||
|
---
|
||
|
中文文档请参看[这里](https://github.com/123sunxiaolin/JLAuthorizationManager/wiki/中文文档)
|
||
|
|
||
|
[Swift-Version](https://github.com/123sunxiaolin/JLAuthorizationManager-Swift)
|
||
|
|
||
|
🔑 **JLAuthorizationManager** is a simple, lightWeight, easy-to-use, complete, thread-safety permission lib for iOS developers to use.
|
||
|
|
||
|
At present, the lib has supported **Objective-C** version and **Swift** version
|
||
|
|
||
|
## Features
|
||
|
- [x] Full coverage, currently supports access to **Photos**, **Camera**, **CellularNetwork**, **Microphone**, **Calendar**, **Reminder**, **Notification**, **Location**, **AppleMusic**, **SpeechRecognizer**, **Siri**, **Bluetooth** etc.
|
||
|
- [x] Easy-to-use, unified interface and separated singe permission.Avoid submitting App Store rejected issues.
|
||
|
- [x] Async fetch authorized permission and callback always in main thread.
|
||
|
- [x] multiple ways to use and flexible use.
|
||
|
|
||
|
Getting Started
|
||
|
------------
|
||
|
### Prerequisites
|
||
|
- Apps using **JLAuthorizationManager** can target: iOS 8.0 or later.
|
||
|
- Xcode 8.0 or later required.
|
||
|
|
||
|
### Installation
|
||
|
- Via **Cocoapods**:
|
||
|
<br>1.Install[Cocoapods](https://guides.cocoapods.org/using/getting-started.html);
|
||
|
<br>2.Run `pod repo update` to make CocoaPods aware of the latest available **JLAuthorizationManager** versions.
|
||
|
<br>3.Due to **Podfile** 's target, add corresponding pod commands as follows,then run `pod install`.In the end, use the .xcworkspace file generated by CocoaPods to work on your project.
|
||
|
|
||
|
```
|
||
|
// pod 'JLAuthorizationManager/All' is equivatent to
|
||
|
pod 'JLAuthorizationManager'
|
||
|
Or
|
||
|
pod 'JLAuthorizationManager/AuthorizationManager'
|
||
|
Or
|
||
|
pod 'JLAuthorizationManager/Camera'
|
||
|
Or
|
||
|
pod 'JLAuthorizationManager/Microphone'
|
||
|
...
|
||
|
|
||
|
```
|
||
|
- Via Manually
|
||
|
<br>1.first,clone project from **https://github.com/123sunxiaolin/JLAuthorizationManager.git**;
|
||
|
<br>2.Then, find document path `JLAuthorizationManager/Classes`, and permission file you need.Need to pay attention to, must add **Base** folder into your project before use.
|
||
|
|
||
|
Tutorials
|
||
|
------------
|
||
|
#### Usage of **JLAuthorizationManager**:
|
||
|
- 1.Via `+ (JLAuthorizationManager *)defaultManager;` singleton method to use.
|
||
|
- 2.add head file `#import "JLAuthorizationManager.h"`
|
||
|
- 3.Use uniform interface:
|
||
|
|
||
|
```
|
||
|
// Geneeral
|
||
|
- (void)JL_requestAuthorizationWithAuthorizationType:(JLAuthorizationType)authorizationType
|
||
|
authorizedHandler:(void(^)())authorizedHandler
|
||
|
unAuthorizedHandler:(void(^)())unAuthorizedHandler;
|
||
|
|
||
|
// Health Data
|
||
|
- (void)JL_requestHealthAuthorizationWithShareTypes:(NSSet*)typesToShare
|
||
|
readTypes:(NSSet*)typesToRead
|
||
|
authorizedHandler:(JLGeneralAuthorizationCompletion)authorizedHandler
|
||
|
unAuthorizedHandler:(JLGeneralAuthorizationCompletion)unAuthorizedHandler;
|
||
|
|
||
|
// Social Account( deprecated at 8.0 or later)
|
||
|
- (void)JL_requestAccountAuthorizationWithAuthorizationType:(JLAuthorizationType)authorizationType
|
||
|
options:(NSDictionary *)options
|
||
|
authorizedHandler:(JLGeneralAuthorizationCompletion)authorizedHandler
|
||
|
unAuthorizedHandler:(JLGeneralAuthorizationCompletion)unAuthorizedHandler
|
||
|
errorHandler:(void(^)(NSError *error))errorHandler;
|
||
|
|
||
|
```
|
||
|
|
||
|
### Usage of single permission - **JLxxxPermission**:
|
||
|
|
||
|
- 1. Every single permission class inherits from base class**JLBasePermisssion**, implementing a unified interface protocol **JLAuthorizationProtocol**:
|
||
|
|
||
|
```
|
||
|
@protocol JLAuthorizationProtocol <NSObject>
|
||
|
|
||
|
/**
|
||
|
return current request authorization type.
|
||
|
*/
|
||
|
@property (nonatomic, assign, readonly) JLAuthorizationType type;
|
||
|
|
||
|
/**
|
||
|
return current authorization status.
|
||
|
In most cases, suggest use 'requestAuthorizationWithCompletion:completion' method.
|
||
|
*/
|
||
|
- (JLAuthorizationStatus)authorizationStatus;
|
||
|
|
||
|
/**
|
||
|
Request authorization and return authorization status in main thread.
|
||
|
*/
|
||
|
- (void)requestAuthorizationWithCompletion:(JLAuthorizationCompletion)completion;
|
||
|
|
||
|
@optional
|
||
|
/**
|
||
|
Wheather add specific permission description key needed.
|
||
|
*/
|
||
|
- (BOOL)hasSpecificPermissionKeyFromInfoPlist;
|
||
|
|
||
|
@end
|
||
|
|
||
|
```
|
||
|
|
||
|
- Basic usage(take request **photos** permission as an example):
|
||
|
|
||
|
```
|
||
|
JLPhotosPermission *permission = [JLPhotosPermission instance];
|
||
|
NSLog(@"current authoriazation status:%@", [self authorizationWithStatus:permission.authorizationStatus]);
|
||
|
NSLog(@"%@ add permission plist description key", permission.hasSpecificPermissionKeyFromInfoPlist ? @"Yes" : @"NO");
|
||
|
[permission requestAuthorizationWithCompletion:^(BOOL granted) {
|
||
|
NSLog(@"%@ : %@", [self titleWithType:permission.type], granted ? @"authorized" : @"unauthorized");
|
||
|
}];
|
||
|
```
|
||
|
|
||
|
- Use singleton method `sharedInstance` to call, when requesting **Location** and **Bluetooth** permission. Take requesting **Location** permission as an excample:
|
||
|
|
||
|
```
|
||
|
JLLocationAlwaysPermission *permission = [JLLocationAlwaysPermission sharedInstance];
|
||
|
NSLog(@"current authoriazation status:%@", [self authorizationWithStatus:permission.authorizationStatus]);
|
||
|
NSLog(@"%@ add permission plist description key", permission.hasSpecificPermissionKeyFromInfoPlist ? @"Yes" : @"No");
|
||
|
[permission requestAuthorizationWithCompletion:^(BOOL granted) {
|
||
|
NSLog(@"%@ : %@", [self titleWithType:permission.type], granted ? @"authorized" : @"unauthorized");
|
||
|
}];
|
||
|
```
|
||
|
|
||
|
- **Health Data** request:
|
||
|
|
||
|
```
|
||
|
HKObjectType *type = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceWalkingRunning];
|
||
|
HKObjectType *type1 = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
|
||
|
NSSet *shareSet = [NSSet setWithObjects:type, type1, nil];
|
||
|
JLHealthPermission *permission = [[JLHealthPermission alloc] initWithShareType:shareSet readTypes:shareSet];
|
||
|
NSLog(@"current authoriazation status:%@", [self authorizationWithStatus:permission.authorizationStatus]);
|
||
|
NSLog(@"%@ add permission plist description key", permission.hasSpecificPermissionKeyFromInfoPlist ? @"Yes" : @"NO");
|
||
|
[permission requestAuthorizationWithCompletion:^(BOOL granted) {
|
||
|
NSLog(@"%@ : %@", [self titleWithType:permission.type], granted ? @"authorized" : @"unauthorized");
|
||
|
}];
|
||
|
```
|
||
|
|
||
|
**For more infomation about useags, please refer to DEMO**.
|
||
|
|
||
|
Tips and Tricks
|
||
|
---------------
|
||
|
|
||
|
- **Don't** forget add authorization Description in `info.plist`.
|
||
|
- if you want to use `HealthKit` or `Siri`,please open switch on `Capabilities`,then system create `xx..entitlements` file automatically.
|
||
|
- if project is not submited to App store, you can use the unified permission manager file `JLAuthorizationManager`; if you need to submit project to the App Store, you need to add the corresponding permission request file according to the business needs, otherwise, the App Store will be rejected due to the addition of useless permissions.
|
||
|
|
||
|
Update Note
|
||
|
---------------
|
||
|
- **v2.1.0** (2019-5-21):fix API available version error.
|
||
|
- **v2.0.2** (2019-2-07):Update podSpec file.
|
||
|
- **v2.0.0** (2019-2-07):Divide all permissions into single permission file to avoid fail to commit **AppStore** and provide various ways to request.
|
||
|
- **v1.1.0** (2019-1-17):Optimize request methods and add notification permission.
|
||
|
- **v1.0.0** (2017-04-13):Provide simple usage of permission for developer and all request usages are in unique class-**JLAuthorizationManager**.
|
||
|
|
||
|
|
||
|
Issues and Improvements
|
||
|
----
|
||
|
|
||
|
- If you find some bugs or things to improve when use the lib, you can open a **issue** directly. If you have a better implementation, welcome to **Pull Request**.
|
||
|
|
||
|
|
||
|
Discussion and Learning
|
||
|
----
|
||
|
- iOS QQ group:**709148214**
|
||
|
- Official Account(Wechat):猿视角(**iOSDevSkills**)
|
||
|
- Wechat:**401788217**
|
||
|
- [Jianshu](https://www.jianshu.com/u/ef991f6d241c)
|
||
|
|
||
|
License
|
||
|
-------
|
||
|
|
||
|
JLAuthorizationManager is under MIT license. See the [LICENSE](https://github.com/123sunxiaolin/JLAuthorizationManager/blob/master/LICENSE) file for more info.
|