The goal of this project is not to create a library that would solve all your problems, but rather provide you with the tools and techniques necessary for creating user-friendly permissions systems.
The “swift permissions” is a library that helps to improve the user flow when asking for permissions. The library uses the Swift language to help with getting and setting permission values.
About
SPPermissions is a library that makes it easier for users to ask for permissions. You may also verify the status of permissions with the following keywords:.authorized,.denied, and.notDetermined.
There are three ready-to-use controllers in the library: list, dialog, and native. iPad, dark mode, and localizations are all supported. See Start Right Away for information on how to get started with the library.
Don’t forget to give the project a star if you like it. Take a look at some of my other libraries:
Permissions
Navigate
Installation
SPPermisions is compatible with iOS 11 and above, and it supports iOS, tvOS, and SwiftUI. SPPermissions needs Xcode 12.0 or above and works with Swift 5+.
Swift Package Manager is a program that allows you to manage your
The Swift Package Manager is a tool for controlling Swift code distribution. It works with the Swift build system to automate the download, compilation, and linking of dependencies.
Using Xcode 12, define SPPermissions in File > Swift Packages > Add Package Dependency…:
https://github.com/ivanvorobei/SPPermissions
After that, choose the permissions you need. But don’t include all of them, otherwise your app may be rejected by Apple.
CocoaPods:
CocoaPods is a Cocoa project dependency management. Visit their website for use and installation information. To use CocoaPods to incorporate SPPermissions, add the following to your Podfile:
‘SPPermissions/Notification’ is a pod.
Due to Apple’s new policy on permission access, you must use subspecs to specify the permissions you wish to access. If you want to access the camera, location, and microphone, for example, you would specify the following:
pod ‘SPPermissions/Camera’ pod ‘SPPermissions/Contacts’ pod ‘SPPermissions/Calendar’ pod ‘SPPermissions/PhotoLibrary’ pod ‘SPPermissions/Notification’ pod ‘SPPermissions/Reminders’ pod ‘SPPermissions/SpeechRecognizer’ pod ‘SPPermissions/SpeechRecognizer’ pod ‘SPPermissions/S
Manually
You may manually integrate SPPermissions if you don’t want to utilize any of the dependency managers. Copy the code from the CONTRIBUTING.md file and add the build flags.
Imports
If you’re using Swift Package Manager, you’ll need to import each module separately:
SPPermissions.import import SPPermissionsCamera import SPPermissionsPhotoLibrary import SPPermissionsCamera import SPPermissionsCamera import SPPermissionsCamera import SPPer
If you use CocoaPods to install, you just need to import one class:
import SPPermissions
It’s needed since the library has been divided into modules. After importing, type SPPermissions to view the available permissions. Take, for example, permission.camera.
Quick Start
/ MARK: 1. Select the rights you require: [SPPermissions.Permission] = [.camera,.camera,.camera,.camera,.camera,.camera,.camera,.camera,.camera,.camera,.camera,.cam .notification] / MARK: 2. Select a current style: Let controller = SPPermissions.list(permissions) controller. / 2a. List Style let controller = SPPermissions.list(permissions) controller. at this time (on: self) let controller = SPPermissions.dialog(permissions) controller.present / 2b. Dialog Style (on: self) let controller = SPPermissions.native(permissions) controller / 2c. Native Style at this time (on: self) 3. Optional: MARK: Check the authorization status (‘authorized,”denied,’notDetermined’ are all options): let authorized = SPPermissions.Permission.authorized.calendar
Check out the Request area for additional information.
Status
Call SPPermissions to verify the status of any permission. Permission:
let authorized = SPPermissions.Permission.authorized.calendar
Denied and notDetermined statuses are also available.
Request
There are three display styles in SPPermissions: Dialog, List, and Native. There are delegates and a data source for each interface. Open Example Apps/SPPermissions.xcodeproj to view an example app.
Dialog
This is a modal notification. When you have less than three permission requests, I suggest utilizing this alert style. Example of application:
let permissions.dialog = SPPermissions.dialog ([.camera, .photoLibrary]) / Texts in the controller controller are ovverided. controller titleText = “Title Text” controller headerText = “Header Text” “Footer Text,” footerText = “Footer Text,” footerText = “Footer Text,” If necessary, set ‘DataSource’ or ‘Delegate’. / By default, project texts and icons are used. dataSource = self controller, controller.dataSource = self controller, controller.dataSource = self controller, controller self = delegate / If you want the controler to dismiss automatically, / make sure that all permissions are in the same state. ‘allPermissionsDeterminated’ is the dismiss mode to use. / By default, the controller is dismissed only if all permissions are granted. .allPermissionsDeterminated = controller.dismissCondition / For the current controller, always use this technique. at this time (on: self)
List
The iPad is supported via a native UITableViewController. When you have more than two permissions, you should use it. Here’s an example of how it’s put to use:
let SPPermissions.list = controller ([.calendar, .camera, .contacts]) / Texts in the controller controller are ovverided. controller titleText = “Title Text” controller headerText = “Header Text” “Footer Text,” footerText = “Footer Text,” footerText = “Footer Text,” If necessary, set ‘DataSource’ or ‘Delegate’. / By default, project texts and icons are used. controller. dataSource is a self-contained controller. self = delegate / If you want the controler to dismiss automatically, / make sure that all permissions are in the same state. ‘allPermissionsDeterminated’ is the dismiss mode to use. / By default, the controller is dismissed only if all permissions are granted. .allPermissionsDeterminated = controller.dismissCondition / For the current controller, always use this technique. at this time (on: self)
Native
With native alerts, you may request permissions. You may request several permissions at the same time:
let permissions.native = SPPermissions.native ([.calendar, .camera, .contacts]) If necessary, set ‘Delegate’. self.controller.delegate = This method should be used for all requests. controller.present (on: self)
DataSource
For data sources that use the SPPermissionsDataSource protocol. You may change the permission cells’ wording and add rejected alerts.
method configure(_ cell: SPPermissionsTableViewCell, for permission: SPPermissions.Permission) extension Controller: SPPermissionsDataSource / You may change the text or color of a cell here. cell.permissionTitleLabel.text = “Title” cell.permissionTitleLabel.text = “Title” cell.permissionDescriptionLabel.text = “Description” cell.permissionDescriptionLabel.text = “Description” / If you want to alter your icon, choose one of these: cell.permissionIconView.setPermissionType(.bluetooth) setCustomImage(UIImage.init(named: “custom-name”)) cell.permissionIconView setCustomView(YourView()) cell.permissionIconView
Alert was turned down.
If a user’s permission is refused, you may send them an alert with the opportunity to check their settings. The following is an example of how you may change the alert text:
SPPermissionsDeniedAlertTexts() texts = SPPermissionsDeniedAlertTexts() texts “Permission refused” messages are used in the titleText. description “Please go to Settings and grant permission,” says the text. action Texts from the “Settings” menu. cancel “Cancel” is the text.
After that, implement and return the following method:
SPPermissionsDeniedAlertTexts? func deniedAlertTexts(for permission: SPPermissions.Permission) / Return texts for custom messages, or return.default for default texts.
Delegate
Set the delegate with protocol SPPermissionsDelegate: to obtain concealed, permitted, or refused events.
SPPermissionsDelegate func was called by extension controller SPPermissionsDelegate func was called by extension controller SPPermissionsDelegate func was permissions: [SPPermissions.Permission]) HidePermissions( permissions: [SPPermissions.Permission]) permission: SPPermissions.Permission) func didAllowPermission( permission: SPPermissions.Permission) func didAllowPermission( permission: SPPermissions.Permission func didDeniedPermission(_ permission: SPPermissions.Permission) func didDeniedPermission(_ permission: SPPermissions.Permission) func didDeniedPermission(_ permission: SPPermissions.Permission
Localizations
SPPermissions includes ready-to-use localizations for the following:
- en Espanol
- Arabic is a language spoken throughout the Arab world.
- de German
- es (Spanish)
- france france
- poland pl
- pt Portuguese
- Ukrainian ukrainian
- Rubble is a Russian currency.
- Simplified Chinese Han zh Hans zh Hans zh Hans z
- It’s Italian.
- zh Hant zh Hant zh Hant zh H
If you wish to add more, please submit a pull request under the folder language id.lproj. Check the DataSource section if you wish to use your own strings.
Info.plist’s keys
Apple requires that you include certain keys to the Info.plist file with descriptions (s). The following is a list of keys for permissions:
let SP be the key Permissions.Permission.bluetooth.usageDescriptionKey
Keys are listed below:
- NSCameraUsageDescription
- NSContactsUsageDescription
- NSCalendarsUsageDescription
- NSMicrophoneUsageDescription
- NSAppleMusicUsageDescription
- NSRemindersUsageDescription
- NSPhotoLibraryUsageDescription
- NSPhotoLibraryAddUsageDescription
- NSSpeechRecognitionUsageDescription
- NSMotionUsageDescription
- NSLocationWhenInUseUsageDescription
- NSLocationAlwaysAndWhenInUseUsageDescription
- NSBluetoothAlwaysUsageDescription
- NSBluetoothPeripheralUsageDescription NSBluetoothPeripheralUsageDescription NSBluetoothPe (iOS 12 and earlier)
- NSUserTrackingUsageDescription
- NSFaceIDUsageDescription
- NSSiriUsageDescription
- NSHealthUpdateUsageDescription
- NSHealthShareUsageDescription
The description should not be used as the key’s name.
Keys will be generated automatically if you utilize the xliff localization export. Create InfoPlist.strings, choose languages in the right side menu, and add keys as keys in the plist-file if you want to perform the localization file manually. See:
“NSCameraUsageDescription” = “This is an explanation of how to use a camera.”
Review of Apple
In May/June 2021, Apple updated its review criteria. When asking permissions, applications should require users to always request the permission and then decide whether to grant or deny it. As a result, the close button in SPPermissions is by default hidden. Run the following code to cause the close button to appear:
/ Controls for showing and hiding the close button. true if showCloseButton is true / Activate or deactivate the drag interaction controller. true if allowSwipeDismiss is true
The button’s title was also modified. Rather than allowing now, use continue. This was requested by the Apple Review Team. Check out this issue for more information.
Contribution
My command of the English language is abysmal. When you read the manual, you’ll see this. I’d want to have clear and attractive documentation. Please contact me at [email protected] or submit a Pull Request if you find any grammatical mistakes in the Readme. Please accept my heartfelt gratitude!
Other Initiatives
I like assisting others. I’ve included a list of libraries that I update on a regular basis. Open the website opensource.ivanvorobei.by to watch video previews of libraries without installing them.
I have libraries with native interfaces and permission management. A collection of helpful addons is also available to help you speed up your development process.
If you want to be notified about new туториaлаs, register at the телерамм-канал.
о слонми и неонтнми адаами, в ате, они ayuda.
/ / / / / / / / / / / / / / / / / / /
GitHub
https://github.com/ivanvorobei/SPPermissions
The “info plist permissions” is a library to improve the user flow when asking permissions. The app will ask for the most important permissions first, and then ask for less important ones.
Related Tags
- the right way to ask users for ios permissions
- ios request permission again
- what is ask permission ui
- ios ask for push notification permission again
- ios permissions dialog