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.
 
 
 
公司电脑 0df78bd3ad bug修改 2 years ago
..
JLAuthorizationManager/Classes bug修改 2 years ago
LICENSE 第一次提交 2 years ago
README.md 第一次提交 2 years ago

README.md

JLAuthorizationManager

Build Status Pod Version Pod Platform System Version Pod License

中文文档请参看这里

Swift-Version

🔑 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

  • Full coverage, currently supports access to Photos, Camera, CellularNetwork, Microphone, Calendar, Reminder, Notification, Location, AppleMusic, SpeechRecognizer, Siri, Bluetooth etc.
  • Easy-to-use, unified interface and separated singe permission.Avoid submitting App Store rejected issues.
  • Async fetch authorized permission and callback always in main thread.
  • 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
    1.InstallCocoapods;
    2.Run pod repo update to make CocoaPods aware of the latest available JLAuthorizationManager versions.
    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'
...

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 classJLBasePermisssion, 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

License

JLAuthorizationManager is under MIT license. See the LICENSE file for more info.