PermissionKit provides a simple framework for requesting permission to access common iOS features.
- Camera
- Contacts
- Events
- Location
- Media Library
- Microphone
- Notifications
- Photo Library
- Reminders
- Speech Recognition (iOS 10+)
Most permissions require a usage description (such as location services) to be included in the info.plist of your application. If the required usage string is not defined in the info.plist, a fatalError() will occur when request(_:) is called indicating which key is missing.
First:
import PermissionKitTo check the status of a permission:
let result = Permission.locationWhenInUse.statusTo check if permission has been requested:
let result = Permission.locationWhenInUse.hasBeenRequestedTo request permission:
Permission.locationWhenInUse.request { status in
// Handle permission status
}or:
// Any iOS version
Permission.notification.request { status in
// Handle permission status
}
// iOS 10 Specific
Permission.notification.request(withOptions: [.alert, .badge, .sound]) { status in
// Handle permission status
}
// iOS 9 Specific
let types: UIUserNotificationType = [.alert, .sound, .badge]
let settings = UIUserNotificationSettings(types: types, categories: nil)
Permission.notification.request(withSettings: settings) { status in
// Handle permission status
}If permission has already been requested the completion block will be executed immediately with the current status. The completion block is always executed on the main thread.
An example iOS app has been included to demo and test functionality. To run the example project, clone the repo, and run pod install from the Example directory first.
iOS 9.3 or later.
PermissionKit is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'PermissionKit', :git => 'https://github.com/seamgen/PermissionKit.git'Sam Gerardi, sgerardi@seamgen.com
PermissionKit is available under the MIT license. See the LICENSE file for more info.