🔑 JLAuthorizationManagerSwift is a simple, lightWeight, easy-to-use, complete, thread-safety permission lib for iOS developers to use.
- 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.
- Apps using JLAuthorizationManagerSwift can target: iOS 8.0 or later.
- Xcode 8.0 or later required.
- Via Cocoapods:
1.InstallCocoapods;
2.Runpod repo update
to make CocoaPods aware of the latest available JLAuthorizationManagerSwift versions.
3.Due to Podfile 's target, add corresponding pod commands as follows,then runpod install
.In the end, use the .xcworkspace file generated by CocoaPods to work on your project.
// pod 'JLAuthorizationManagerSwift/All' is equivatent to
pod 'JLAuthorizationManagerSwift'
Or
pod 'JLAuthorizationManagerSwift/AuthorizationManager'
Or
pod 'JLAuthorizationManagerSwift/Camera'
Or
pod 'JLAuthorizationManagerSwift/Microphone'
...
- Via Manually
1.first,clone project from https://github.com/123sunxiaolin/JLAuthorizationManager.git;
2.Then, find document pathJLAuthorizationManager/Classes
, and permission file you need.Need to pay attention to, must add Base folder into your project before use.
- 1.Via
shared
singleton method to use. - 2.Use uniform interface:
// Geneeral
public func requestPermission(_ type: PermissionType,
completion: @escaping PermissionCompletion)
// Health Data
public func requestHealthPermission(_ typesToShare: Set<HKSampleType>,
typesToRead: Set<HKObjectType>,
completion: @escaping PermissionCompletion)
-
- Every single permission class inherits from base classBasePermisssion, implementing a unified interface protocol Permission:
public protocol Permission where Self: BasePermission {
/// Permission type
var type: PermissionType { get }
/// Current authorized status
func authorizedStatus() -> AuthorizedStatus
/// Request current permission
func requestPermission(_ completion: @escaping AuthorizedCompletion)
}
- Basic usage(take request photos permission as an example):
let permission = PhotosPermission()
print("\(type.title) -> status:\(permission.authorizedStatus())")
permission.requestPermission { granted in
print(granted ? "Authorized -> \(type.title)" : "unAuthorized -> \(type.title)")
}
- Use singleton method
shared
to call, when requesting Location and Bluetooth permission. Take requesting Location permission as an excample:
let permission = LocationAlwaysPermission.shared
print("\(type.title) -> status:\(permission.authorizedStatus())")
permission.requestPermission { granted in
print(granted ? "Authorized -> \(type.title)" : "unAuthorized -> \(type.title)")
}
- Health Data request:
let permission = HealthPermission(typesToShare, typesToRead: typesToRead)
print("\(type.title) -> status:\(permission.authorizedStatus())")
permission.requestPermission { granted in
print(granted ? "Authorized -> \(type.title)" : "unAuthorized -> \(type.title)")
}
For more infomation about useags, please refer to DEMO.
- Don't forget add authorization Description in
info.plist
. - if you want to use
HealthKit
orSiri
,please open switch onCapabilities
,then system createxx..entitlements
file automatically. - if project is not submited to App store, you can use the unified permission manager file
JLAuthorizationManagerSwift
; 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.
- v1.0.4 (2019-2-12):Fix bugs.
- v1.0.3 (2019-1-18):Update project structure.
- v1.0.0 (2019-1-17):Divide all permissions into single permission file to avoid fail to commit AppStore and provide various ways to request..
- 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.
- iOS QQ group:709148214
- Official Account(Wechat):猿视角(iOSDevSkills)
- Wechat:401788217
- Jianshu
Jacklin, 401788217@qq.com
JLAuthorizationManagerSwift is available under the MIT license. See the LICENSE file for more info.