Latest 1.0.4
Homepage https://github.com/123sunxiaolin/JLAuthorizationManager-Swift
License MIT
Platforms ios 9.0
Authors

Build Status
Version
License
Platform

中文文档

Objective-C 版本 请戳这

🔑 JLAuthorizationManagerSwift is a simple, lightWeight, easy-to-use, complete, thread-safety permission lib for iOS developers to use.

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 JLAuthorizationManagerSwift 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 JLAuthorizationManagerSwift 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 'JLAuthorizationManagerSwift/All' is equivatent to
pod 'JLAuthorizationManagerSwift' 
Or
pod 'JLAuthorizationManagerSwift/AuthorizationManager'
Or
pod 'JLAuthorizationManagerSwift/Camera'
Or
pod 'JLAuthorizationManagerSwift/Microphone'
...

Tutorials

Usage of JLAuthorizationManager

  • 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)

Usage of single permission – xxxPermission:

    1. 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.

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 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.

Update Note

  • 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..

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
  • Public Wechat:猿视角(iOSDevSkills)
  • Wechat:401788217
  • Jianshu

Author

Jacklin, [email protected]

License

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

Latest podspec

{
    "name": "JLAuthorizationManagerSwift",
    "version": "1.0.4",
    "summary": "In swift, a Project can provide uniform method for system authorization accesses!",
    "description": "In swift, a Project can provide uniform method for system authorization accesses!",
    "homepage": "https://github.com/123sunxiaolin/JLAuthorizationManager-Swift",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Jacklin": "[email protected]"
    },
    "source": {
        "git": "https://github.com/123sunxiaolin/JLAuthorizationManager-Swift.git",
        "tag": "1.0.4"
    },
    "social_media_url": "https://123sunxiaolin.github.io",
    "platforms": {
        "ios": "9.0"
    },
    "swift_version": "4.2",
    "source_files": "JLAuthorizationManagerSwift/Classes/**/*",
    "default_subspecs": "All",
    "subspecs": [
        {
            "name": "All",
            "source_files": [
                "JLAuthorizationManagerSwift/Classes/Base/",
                "JLAuthorizationManagerSwift/Classes/Permissions/"
            ]
        },
        {
            "name": "Base",
            "source_files": "JLAuthorizationManagerSwift/Classes/Base/*"
        },
        {
            "name": "AuthorizationManager",
            "source_files": "JLAuthorizationManagerSwift/Classes/AuthorizationManager/*",
            "dependencies": {
                "JLAuthorizationManagerSwift/Base": []
            }
        },
        {
            "name": "Camera",
            "source_files": "JLAuthorizationManagerSwift/Classes/Permissions/CameraPermission.swift",
            "dependencies": {
                "JLAuthorizationManagerSwift/Base": []
            }
        },
        {
            "name": "Microphone",
            "source_files": [
                "JLAuthorizationManagerSwift/Classes/Permissions/AudioPermission.swift",
                "JLAuthorizationManagerSwift/Classes/Permissions/MicrophonePermission.swift"
            ],
            "dependencies": {
                "JLAuthorizationManagerSwift/Base": []
            }
        },
        {
            "name": "Notification",
            "source_files": "JLAuthorizationManagerSwift/Classes/Permissions/NotificationPermission.swift",
            "dependencies": {
                "JLAuthorizationManagerSwift/Base": []
            }
        },
        {
            "name": "Photos",
            "source_files": "JLAuthorizationManagerSwift/Classes/Permissions/PhotosPermission.swift",
            "dependencies": {
                "JLAuthorizationManagerSwift/Base": []
            }
        },
        {
            "name": "CellularNetwork",
            "source_files": "JLAuthorizationManagerSwift/Classes/Permissions/CellularNetworkPermission.swift",
            "dependencies": {
                "JLAuthorizationManagerSwift/Base": []
            }
        },
        {
            "name": "Contact",
            "source_files": "JLAuthorizationManagerSwift/Classes/Permissions/ContactPermission.swift",
            "dependencies": {
                "JLAuthorizationManagerSwift/Base": []
            }
        },
        {
            "name": "Events",
            "source_files": "JLAuthorizationManagerSwift/Classes/Permissions/EventsPermission.swift",
            "dependencies": {
                "JLAuthorizationManagerSwift/Base": []
            }
        },
        {
            "name": "Reminder",
            "source_files": "JLAuthorizationManagerSwift/Classes/Permissions/ReminderPermission.swift",
            "dependencies": {
                "JLAuthorizationManagerSwift/Base": []
            }
        },
        {
            "name": "Location",
            "source_files": [
                "JLAuthorizationManagerSwift/Classes/Permissions/LocationInUsePermission.swift",
                "JLAuthorizationManagerSwift/Classes/Permissions/LocationAlwaysPermission.swift"
            ],
            "dependencies": {
                "JLAuthorizationManagerSwift/Base": []
            }
        },
        {
            "name": "AppleMusic",
            "source_files": "JLAuthorizationManagerSwift/Classes/Permissions/AppleMusicPermission.swift",
            "dependencies": {
                "JLAuthorizationManagerSwift/Base": []
            }
        },
        {
            "name": "SpeechRecognizer",
            "source_files": "JLAuthorizationManagerSwift/Classes/Permissions/SpeechRecognizerPermission.swift",
            "dependencies": {
                "JLAuthorizationManagerSwift/Base": []
            }
        },
        {
            "name": "Siri",
            "source_files": "JLAuthorizationManagerSwift/Classes/Permissions/SiriPermission.swift",
            "dependencies": {
                "JLAuthorizationManagerSwift/Base": []
            }
        },
        {
            "name": "Motion",
            "source_files": "JLAuthorizationManagerSwift/Classes/Permissions/MotionPermission.swift",
            "dependencies": {
                "JLAuthorizationManagerSwift/Base": []
            }
        },
        {
            "name": "Bluetooth",
            "source_files": [
                "JLAuthorizationManagerSwift/Classes/Permissions/BluetoothPermission.swift",
                "JLAuthorizationManagerSwift/Classes/Permissions/BluetoothPeripheralPermission.swift"
            ],
            "dependencies": {
                "JLAuthorizationManagerSwift/Base": []
            }
        },
        {
            "name": "Health",
            "source_files": "JLAuthorizationManagerSwift/Classes/Permissions/HealthPermission.swift",
            "dependencies": {
                "JLAuthorizationManagerSwift/Base": []
            }
        }
    ]
}

Pin It on Pinterest

Share This