Library for ask permissions. You can check state of permissions, available .authorized
, .denied
& .notDetermined
.
Available ready-use controllers for reqeust permissions: list, dialog & native. Support iPad, dark mode and RTL. Interface in an Apple style. For beginner see Quick Start.
If you like the project, don't forget to put star ★
and follow me on GitHub:
- Installation
- Imports
- Quick Start
- Status
- Request
- DataSource
- Delegate
- Localizations
- Keys in Info.plist
- Apple Review
- Сontribution
- Other Projects
- Russian Community
Ready to use on iOS 11+. Supports iOS, tvOS and SwiftUI. Works with Swift 5+. Requires Xcode 12.5 and higher.
The Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.
To integrate SPPermissions
into your Xcode project using Xcode 12, specify it in File > Swift Packages > Add Package Dependency...
:
https://github.com/ivanvorobei/SPPermissions
Next choose the permissions you need. But don't add all of them, because apple will reject your app.
CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate SPPermissions
into your Xcode project using CocoaPods, specify it in your Podfile
:
pod 'SPPermissions/Notification'
Due to Apple's new policy regarding permission access you need to specifically define what kind of permissions you want to access using subspecs. For example if you want to access Camera
, Location
& Microphone
you define the following:
pod 'SPPermissions/Camera'
pod 'SPPermissions/LocationAlways'
pod 'SPPermissions/Microphone'
Available subspecs
pod 'SPPermissions/Camera'
pod 'SPPermissions/Contacts'
pod 'SPPermissions/Calendar'
pod 'SPPermissions/PhotoLibrary'
pod 'SPPermissions/Notification'
pod 'SPPermissions/Microphone'
pod 'SPPermissions/Reminders'
pod 'SPPermissions/SpeechRecognizer'
pod 'SPPermissions/LocationWhenInUse'
pod 'SPPermissions/LocationAlways'
pod 'SPPermissions/Motion'
pod 'SPPermissions/Music'
pod 'SPPermissions/Bluetooth'
pod 'SPPermissions/Tracking'
pod 'SPPermissions/FaceID'
pod 'SPPermissions/Siri'
pod 'SPPermissions/Health'
If you prefer not to use any of dependency managers, you can integrate SPPermissions
into your project manually. Copy code and add compile flags from CONTRIBUTING.md file.
If you install via Swift Package Manager, you shoud import each module:
import SPPermissions
import SPPermissionsCamera
import SPPermissionsPhotoLibrary
If you install via CocoaPods, you only need to import one class:
import SPPermissions
Its required because library split to modules. After importing you'll see available permissions by typing SPPermissions.Permission.camera
for example.
// MARK: 1. Choose the permissions you need:
let permissions: [SPPermissions.Permission] = [.camera, .notification]
// MARK: 2. Choose present style:
// 2a. List Style
let controller = SPPermissions.list(permissions)
controller.present(on: self)
// 2b. Dialog Style
let controller = SPPermissions.dialog(permissions)
controller.present(on: self)
// 2c. Native Style
let controller = SPPermissions.native(permissions)
controller.present(on: self)
// MARK: 3. Optional: Check permission state (available `authorized`, `denied`, `notDetermined`):
let authorized = SPPermissions.Permission.calendar.authorized
For more details check Request section.
To check the state of any permission, call SPPermissions.Permission
:
let authorized = SPPermissions.Permission.calendar.authorized
Also available denied
& notDetermined
.
Now available 3 present styles: Dialog
, List
and Native
. Each interface has delegates and a data source. If you want see an example app, open Example Apps/SPPermissions.xcodeproj
.
This is a modal alert. I recommend using this alert style when you have less than three requested permissions. Usage example:
let controller = SPPermissions.dialog([.camera, .photoLibrary])
// Ovveride texts in controller
controller.titleText = "Title Text"
controller.headerText = "Header Text"
controller.footerText = "Footer Text"
// Set `DataSource` or `Delegate` if need.
// By default using project texts and icons.
controller.dataSource = self
controller.delegate = self
// Always use this method for present
controller.present(on: self)
Native UITableViewController
with support for the iPad. Use it when you have more than two permissions. An example of how it is used:
let controller = SPPermissions.list([.calendar, .camera, .contacts])
// Ovveride texts in controller
controller.titleText = "Title Text"
controller.headerText = "Header Text"
controller.footerText = "Footer Text"
// Set `DataSource` or `Delegate` if need.
// By default using project texts and icons.
controller.dataSource = self
controller.delegate = self
// Always use this method for present
controller.present(on: self)
Request permissions with native alerts. You can request many permissions at once:
let controller = SPPermissions.native([.calendar, .camera, .contacts])
// Set `Delegate` if need.
controller.delegate = self
// Always use this method for request.
controller.present(on: self)
For data source using protocol SPPermissionsDataSource
. You can customise the permission cells / provide denied alert texts.
extension Controller: SPPermissionsDataSource {
func configure(_ cell: SPPermissionsTableViewCell, for permission: SPPermissions.Permission) {
// Here you can customise cell, like texts or colors.
cell.permissionTitleLabel.text = "Title"
cell.permissionDescriptionLabel.text = "Description"
// If you need change icon, choose one of this:
cell.permissionIconView.setPermissionType(.bluetooth)
cell.permissionIconView.setCustomImage(UIImage.init(named: "custom-name"))
cell.permissionIconView.setCustomView(YourView())
}
}
If permission denied, you can provide alert to user with an option to open settings. Here you can customise the alert text:
let texts = SPPermissionDeniedAlertTexts()
texts.titleText = "Permission denied"
texts.descriptionText = "Please, go to Settings and allow permission."
texts.actionText = "Settings"
texts.cancelText = "Cancel"
Next implement method and return:
func deniedAlertTexts(for permission: SPPermissions.Permission) -> SPPermissionDeniedAlertTexts? {
// Custom texts:
return texts
// or default texts:
// return .default
}
To get "hidden", "allowed" or "denied" events , set the delegate with protocol SPPermissionsDelegate
:
extension Controller: SPPermissionsDelegate {
func didHidePermissions(_ permissions: [SPPermissions.Permission]) {}
func didAllowPermission(_ permission: SPPermissions.Permission) {}
func didDeniedPermission(_ permission: SPPermissions.Permission) {}
}
App has ready-use localisation for:
- English
en
- Arabic
ar
- German
de
- Spanish
es
- French
fr
- Polish
pl
- Portuguese
pt
- Ukrainian
uk
- Russian
ru
- Chinese Simplified Han
zh_Hans
- Italian
it
If you want add more, please, create folder language_id.lproj
and make pull request. If you want use your custom strings, check DataSource section.
You need to add some keys to the Info.plist
file with descriptions. You can get plist keys for permission:
let key = SPPermissions.Permission.bluetooth.usageDescriptionKey
List of keys:
- NSCameraUsageDescription
- NSContactsUsageDescription
- NSCalendarsUsageDescription
- NSMicrophoneUsageDescription
- NSAppleMusicUsageDescription
- NSRemindersUsageDescription
- NSPhotoLibraryUsageDescription
- NSPhotoLibraryAddUsageDescription
- NSSpeechRecognitionUsageDescription
- NSMotionUsageDescription
- NSLocationWhenInUseUsageDescription
- NSLocationAlwaysAndWhenInUseUsageDescription
- NSBluetoothAlwaysUsageDescription
- NSBluetoothPeripheralUsageDescription (iOS 12 and earlier)
- NSUserTrackingUsageDescription
- NSFaceIDUsageDescription
- NSSiriUsageDescription
- NSHealthUpdateUsageDescription
- NSHealthShareUsageDescription
Do not use the description as the name of the key.
If you use xliff localization export, keys will be create automatically. If you prefer do the localization file manually, you need to create InfoPlist.strings
, select languages in the right side menu and add keys as keys in plist-file. See:
"NSCameraUsageDescription" = "Here description of usage camera";
Apple changed its review guidelines. When requesting permissions, apps should users to always request and make a decision whether to allow or decline. For this reason, the close button is hidden by default. If you want to force show the close button, run the following code:
// Work for any style
controller.showCloseButton = true
Also changed title for button. Instead of allow
now using continue
. The Apple Review Team asked for this. For details, check outthis issue.
My English is very bad. You can see this once you read the documentation. I would really like to have clean and nice documentation. If you can fix Readme, please contact me hello@ivanvorobei.by or make Pull Request. I'm willing to pay if need.
Floating indicator, mimicrate to indicator which appear when silent mode turn on / off. Support large texts and has ready-use animatable icons like done
and error
.
You can find this alerts in AppStore after feedback or after added song to library in Apple Music. Contains popular Done, Heart presets and many other. Done preset present with draw path animation like original. Also available simple present message without icon. Usage in one line code.
Animation of widgets from iOS 14. 3D transform with dynamic shadow. Look video preview. Available deep customisation 3D and shadow. Also you can use static transform without animation.
Simplifies working with animated changes in table and collections. Apple's diffable API required models for each object type. If you want use it in many place, you pass time to implement it and get over duplicates codes. This project help do it elegant with shared models and special cell providers. Support side bar iOS14 and already has native cell providers and views.
Collection of native Swift extensions to boost your development. Support tvOS and watchOS.
В телеграм-канале Код Воробья пишу о iOS разработке. Помощь можно найти в нашем чате. Видео-туториалы выклыдываю на YouTube: