Ask permissions on Swift. Available List, Dialog & Native interface. Can check state permission.

Overview

SPPermissions

About

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:

https://github.com/ivanvorobei

Navigate

Installation

Ready for use on iOS 11+. Support iOS, tvOS and SwiftUI. Works with Swift 5+. Required Xcode 12.5 and higher.

Swift Package Manager

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 permissions, which you need. Don't add all permissions, becouse apple will reject you app.

CocoaPods:

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/MediaLibrary'
pod 'SPPermissions/Bluetooth'
pod 'SPPermissions/Tracking'

Manually

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.

Imports

If you install via Swift Package Manager, you shoud import each module:

import SPPermissions
import SPPermissionsCamera
import SPPermissionsPhotoLibrary

If you install via CocoaPods, you shoud simple import one class:

import SPPermissions

Its required becouse library split to modules. After import you see available permission by typing SPPermissions.Permission.camera for example.

Quick Start

// MARK: 1. Choose permissions, which 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 usage section.

Usage

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.

Dialog

This is a modal alert. I recommend to use of this alert style when your requested permissions are less than three. 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)

List

Native UITableViewController with support for the iPad. Use it with 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)

Native

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)

Permissions

To check the state of any permission, call SPPermissions.Permission:

let authorized = SPPermissions.Permission.calendar.authorized

Also available denied & notDetermined.

DataSource

For data source using protocol SPPermissionsDataSource. You can customise cell for permission or provide denied alert texts.

extension Controller: SPPermissionsDataSource {
    
    func configure(_ cell: SPPermissionsTableViewCell, for permission: SPPermissions.Permission) {
        // Here you can customise cell, like texts or colors.
    }
}

Denied alert

If permission denied, you can provide alert to user for propose open settings. Here you can customise text of it alert:

let texts = SPPermissionDeniedAlertTexts()
texts.titleText = "Permission denied"
texts.descriptionText = "Please, go to Settings and allow permission."
texts.buttonText = "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
}

Delegate

For get events about hide, allowed or denied, set delegate of protocol SPPermissionsDelegate:

extension Controller: SPPermissionsDelegate {
    
    func didHidePermissions(_ permissions: [SPPermissions.Permission]) {}
    func didAllowPermission(_ permission: SPPermissions.Permission) {}
    func didDeniedPermission(_ permission: SPPermissions.Permission) {}
}

Localizations

App has ready-use localisation stirngs for en, ar & ru. 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.

Keys in Info.plist

You need to add some keys to the Info.plist file with descriptions. List of keys:

  • NSCameraUsageDescription
  • NSContactsUsageDescription
  • NSCalendarsUsageDescription
  • NSMicrophoneUsageDescription
  • NSAppleMusicUsageDescription
  • NSSpeechRecognitionUsageDescription
  • NSMotionUsageDescription
  • NSLocationWhenInUseUsageDescription
  • NSLocationAlwaysAndWhenInUseUsageDescription
  • NSLocationAlwaysUsageDescription (iOS 10 and earlier)
  • NSBluetoothAlwaysUsageDescription
  • NSBluetoothPeripheralUsageDescription (iOS 12 and earlier)
  • NSUserTrackingUsageDescription

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";

FAQ

Why library looks complex and have modules?

Apple reject app with you import all frameworks and not request it. SPPermissions imported only code, which you choose. Support moduls struct is hard and may looks complex. I tried to make using the library as simple as possible.

Why I not see permission?

Check imports if you install via Swift Package Manager. If you install via CocoaPods, you podfile shoud have second path with module name.

I want make PR

Thanks for contribution! Please, support code style and test iOS and tvOS versions before. For more details about codestyle see CONTRIBUTING.md.

Other Projects

SPIndicator

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.

SPAlert

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.

SPPerspective

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.

SPDiffable

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.

SparrowKit

Collection of native Swift extensions to boost your development. Support tvOS and watchOS.

Russian Community

В телеграм-канале Код Воробья пишу о iOS разработке. Помощь можно найти в нашем чате. Видео-туториалы выклыдываю на YouTube:

Tutorials on YouTube

Comments
  • App crashes in isAllowed method in SPPermission enum

    App crashes in isAllowed method in SPPermission enum

    Fatal error: SPPermission - Notification not import. See Readme: https://github.com/ivanvorobei/SPPermission: file /Users/*/<project name>/Carthage/Checkouts/SPPermission/Source/SPPermission/SPPermission.swift, line 89
    (lldb) 
    

    Same problem occurs on previous version (4.0), but is gone on version 3.1.1

    Screen Shot 2019-06-14 at 13 44 21 bug 
    opened by rkyslyy 34
  • whose view is not in the window hierarchy!

    whose view is not in the window hierarchy!

    I get this error: "Sparrow.SPRequestPermissionDialogInteractiveViewController: ... whose view is not in the window hierarchy!".

    I setup the RequestPermission like this:

    var permissionAssistant = SPRequestPermissionAssistant.modules.dialog.interactive.create(with: [.Location, .PhotoLibrary, .Notification])
    
    override func viewDidAppear(animated: Bool) {
            permissionAssistant.present(on: self)
    }
    

    Thanks.

    opened by pbeneteau 20
  • Problem with SPM

    Problem with SPM

    When using SPM to add the library, it crashes even if the xcconfig file has been correctly added and use to configure the project. Perhaps due to the fact that with SPM the complete SPPermissions library is added.

    When using Pod with only the 2 modules i need, it works fine.

    bug 
    opened by MoveUpwardsDev 19
  • AppStore rejection

    AppStore rejection

    Just an FYI…Apple rejected an update to our app this week due to the ability to dismiss the SPPermissions dialog without presenting the native Apple Permissions dialog(s).

    They stated that while we can still display a popup describing the permissions we want and why we want it, we cannot allow the user to dismiss that dialog and skip the actual native request.

    This seems to be a new rule that ties into the new App Tracking Permissions (which we do not use), but does affect all permissions.

    opened by ehlersd 17
  • Access denied

    Access denied

    Reproduce: Presenting SPRequest.Dialog -> Denie access (e.g. for camera) -> you will not see the altert to get directed to settings.

    This worked with the last version.

    opened by florolf1 17
  • didRegisterForRemoteNotificationsWithDeviceToken

    didRegisterForRemoteNotificationsWithDeviceToken

    When accepting the enable notification .. didRegisterForRemoteNotificationsWithDeviceToken is not being called... I would expect that to be the case? How else would I go about getting the device token after they accepted enabling notifications?

    opened by croossin 16
  • 6.x configure button colors not changed the color

    6.x configure button colors not changed the color

    Not sure if this is a bug or a 5.x -> 6.x migration issue on my part, but:

    in: func configure

    in 5.x, the following would turn the icons and buttons purple:

    // Colors
            cell.iconView.color = .systemPurple
            cell.button.allowedBackgroundColor = .systemPurple
            cell.button.allowTitleColor = .systemPurple
    

    In 6x, the following turns the icons purple, but not the buttons:

    // Colors
            cell.permissionDrawIconView.tintColor = .systemPurple
            cell.permissionButton.allowedBackgroundColor = .systemPurple
            cell.permissionButton.allowTitleColor = .systemPurple
    

    Is that syntax incorrect or is it a bug w/ the color configuration? Thank you in advance!

    bug 
    opened by jminutaglio 15
  • Problem..

    Problem..

    Hello sir, i'm trying to implement the notification permission and i got a crash , the famous :

    " Fatal error: SPPermissions - Notification not import. Problem NOT with usage description key. I recomend to see installation guide: https://youtu.be/1kR5HGVhJfk. More details in Readme: "

    i saw the guide video in youtube but i cannot understand russian :(

    i need to import all the source folder ? or should i need to import just the .config permissionfile ? where to put it ? please help :(

    opened by ghost 15
  • SPPermission not able to check for permissions

    SPPermission not able to check for permissions

    When calling the function hasPermission() the console shows this error

    Fatal error: SPPermission - Camera not import. See Readme: https://github.com/ivanvorobei/SPPermission

    I am aware of the situation with the permissions and Apple's new policy. But I am using Carthage and in SPPermission Readme doesn't say that I have to do anything extra. Is there any way to solve this issue?

    bug 
    opened by davidvpe 15
  • Question: Is there a way to keep the status bar displayed?

    Question: Is there a way to keep the status bar displayed?

    Hi,

    Firstly I must say your project is great and extremely handy. Really appreciate your work.

    I wanted to ask about the status bar and it's animation in the app. I will provide some screenshots to illustrate what i mean.

    IMG_1514

    IMG_1512

    As you can see in the first screen shot, I show the SPPermissionDialog on top of a Video Recording View Controller i've set up. In the second screen shot, once the dialog has stopped showing, the status bar pushes my top most views down a bit and suddenly my camera preview view is overlapping with my record button.

    I have tried to relayout the subviews once the didHide() function is called in the SPPermissionDialogDelegate, and I have tried to set prefersStatusBarHidden to false in the SPPermissionDialogController code, but both of these haven't helped. I've also gone through the Controller code and found where you are operating on or with the status bar and tried to set the value to statically keep the status bar showing, but that also hasn't worked.

    I was wondering if you have any suggestions on how I can deal with this scenario.

    Thank you, Alan

    bug 
    opened by alanpridestar 11
  • Message when access denied

    Message when access denied

    Firstly, thanks for doing this awesome project!🙂 I would like to use this library in my app, so I have a question. I ran example project on a real device. My question probably relates to this. So, when the user denies access to a calendar for example. I didn't see any message asking the user to go to settings. Is this message exists? Maybe I missed something? Thanks for help in advance. example_app

    opened by Yurssoft 11
  • Suggestion: add callback method to determine whether to authorize status

    Suggestion: add callback method to determine whether to authorize status

    Steps to reproduce:

    1. Open the app for the first time and request notification permission. Click Allow
    2. Manually open the system settings page and turn off the App notification permission
    3. Open the app again and request notification permission. Calling the request method will still take the request callback scheme
    image bug 
    opened by GPX-NSlog 1
  • Bluetooth status (powered)

    Bluetooth status (powered)

    We can check the status o f the bluetooth if it's turned on or off

    Should be great to check that too with PermissionsKit

    var manager:CBCentralManager!
    
     viewDidLoad() {      // Or init()
         manager          = CBCentralManager()
         manager.delegate = self
     }
    
    func centralManagerDidUpdateState(_ central: CBCentralManager) {
        switch central.state {
        case .poweredOn:
            break
        case .poweredOff:
            print("Bluetooth is Off.")
            break
        case .resetting:
            break
        case .unauthorized:
            break
        case .unsupported:
            break
        case .unknown:
            break
        default:
            break
        }
    }
    
    enhancement 
    opened by CavalcanteLeo 4
  • Delegate method when user taps on

    Delegate method when user taps on "settings" or "cancel"

    When you deny, PermissionsKit show up a alert with 2 options: "cancel" and "settings", you can change the text of settings using deniedPermissionAlertTexts

    But I need to know if the user has tapped in some of these 2 buttons, and it's private

    https://github.com/sparrowcode/PermissionsKit/blob/84ee165d34306d837cb80995de770be4726751c2/Sources/PermissionsKit/Services/PresenterService.swift#L42

    https://github.com/sparrowcode/PermissionsKit/blob/84ee165d34306d837cb80995de770be4726751c2/Sources/PermissionsKit/Models/Permission.swift#L56

    Is there a way to detect that?

    enhancement 
    opened by CavalcanteLeo 2
  • Local Network Permission

    Local Network Permission

    Feature Description Describe what functionality you want to see.

    Thank you for your development of this library. I have a small demand. When the application is started for the first time, it mistakenly touches that it is not allowed to use the network permission. How can I know that the user does not open the network permission and let the user go to the setting page to open the network permission?

    let data = CTCellularData()
            let state = data.restrictedState
            switch state {
              case .notRestricted:
              DispatchQueue.main.async {
                  authorizedHandler()
              }
              default:
              DispatchQueue.main.async {
                  unAuthorizedHandler()
              }
            }
    
    enhancement wait more 
    opened by z234009184 19
Releases(9.0.2)
Owner
Ivan Vorobei
iOS Developer
Ivan Vorobei
A unified API to ask for permissions on iOS

Permission exposes a unified API to request permissions on iOS. Usage • Example • Installation • License Usage Permission Permission.swift PermissionS

Damien 2.9k Dec 27, 2022
A unified API to ask for permissions on iOS

PAPermissions PAPermissions is a fully customizable and ready-to-run library to handle permissions through a ViewController Right now it supports out

Pasquale Ambrosini 694 Oct 17, 2022
AREK is a clean and easy way to request any kind of iOS permission (with some nifty features 🤖)

AREK is a clean and easy to use wrapper over any kind of iOS permission written in Swift. Why AREK could help you building a better app is well descri

Ennio Masi 961 Dec 20, 2022
Make permission request easier.

Proposer Proposer provides a single API to request permission for access Camera, Photos, Microphone, Contacts, Reminders, Calendar, Location or Notifi

null 855 Nov 3, 2022
A polite and unified way of asking for permission on iOS

ISHPermissionKit ISHPermissionKit provides a polite and unified way of asking for permission on iOS. It also provides UI to explain the permission req

iosphere GmbH 619 Nov 3, 2022
A visual permission manager for iOS

VWWPermissionKit We've all been there. You get started on your latest and greatest app when you have to add logic to prompt the user for permissions b

Zakk Hoyt 144 Feb 24, 2022
The application shows all contacts from the iPhone Contact list

Contacts The application shows all contacts from the iPhone Contact list. You can see more details about contact by tapping in contact. Every change i

Karen 0 Nov 24, 2021
HealthKitToFhir Swift Library

HealthKitToFhir Swift Library Relevant for my master thesis is the following: th

null 0 Dec 22, 2021
An iOS pre-permissions utility that lets developers ask users on their own dialog for calendar, contacts, location, photos, reminders, twitter, push notifications and more, before making the system-based permission request.

An iOS pre-permissions utility that lets developers ask users on their own dialog for calendar, contacts, location, photos, reminders, twitter, push notifications and more, before making the system-based permission request.

Joe L 420 Dec 22, 2022
Cluster's reusable pre-permissions utility that lets developers ask the users on their own dialog for photos or contacts access, before making the system-based request.

Cluster's reusable pre-permissions utility that lets developers ask the users on their own dialog for photos or contacts access, before making the system-based request. This is based on the Medium post by Cluster describing the different ways to ask for iOS permissions (https://medium.com/p/96fa4eb54f2c).

Riz 1.2k Sep 29, 2022
The "Ask Me" is simple iOS application which shows answer on the screen everytime when the user press the ask button

The "Ask Me" is simple iOS application which shows answer on the screen everytime when the user press the ask button. This application is build and design by Chetan Parate using Xcode and Swift.

Chetan Parate 0 Oct 27, 2021
A simple and attractive AlertView to ask permission to your users for Push Notification.

A simple and attractive AlertView **to ask permission to your users for Push Notification.** PRESENTATION Ask permission to user for push notification

Boisney Philippe 37 Mar 23, 2022
A unified API to ask for permissions on iOS

Permission exposes a unified API to request permissions on iOS. Usage • Example • Installation • License Usage Permission Permission.swift PermissionS

Damien 2.9k Dec 27, 2022
A unified API to ask for permissions on iOS

PAPermissions PAPermissions is a fully customizable and ready-to-run library to handle permissions through a ViewController Right now it supports out

Pasquale Ambrosini 694 Oct 17, 2022
A highly customizable alert dialog controller that mimics Snapchat's alert dialog.

AZDialogViewController A highly customizable alert dialog controller that mimics Snapchat's alert dialog. Screenshots Installation CocoaPods: pod 'AZD

Antonio Zaitoun 771 Dec 11, 2022
A super easy way to check if the installed app has an update available. It is built with simplicity and customisability in mind and comes with pre-written tests.

UpdateAvailableKit This is UpdateAvailableKit: a super easy way to check if the installed app has an update available. It is built with simplicity and

Swapnanil Dhol 22 Jan 5, 2023
A tool to check which keychain items are available to an attacker once an iOS device has been jailbroken

Keychain Dumper Usage All that should be needed to use keychain_dumper is the binary that is checked in to the Keychain-Dumper Git repository. This bi

Patrick Toomey 1.2k Dec 28, 2022
React Native Todo List example app which uses Redux for managing app state

react-native-redux-todo-list A sample todo list app developed by using React Native and Redux. How to run the app Install react-native If you don't ha

null 43 Oct 11, 2022
Cordova plugin to display a native color-picker dialog

Color Picker Plugin for Cordova (cordova-plugin-color-picker) Description This plugin allows you to display a color-picker native dialog in iOS and An

Antonio Vargas 1 May 10, 2022
Async State Machine aims to provide a way to structure an application thanks to state machines

Async State Machine Async State Machine aims to provide a way to structure an application thanks to state machines. The goal is to identify the states

Thibault Wittemberg 27 Nov 17, 2022