Simple request permission with native UI and interactive animation
Clone or download
Latest commit 21e1d54 Dec 16, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Example Update to 2.4.8 Dec 14, 2018
Source/SPPermission Update to 2.4.8 Dec 14, 2018
.gitignore removed .DS_Store Nov 18, 2018
LICENSE Initial commit Feb 16, 2017
README.md Update README.md Dec 15, 2018
SPPermission.podspec Update to 2.4.8 Dec 14, 2018

README.md

About

This project is about managing permissions with the customizable visual effects. Beautiful dialog increases the chance of approval (which is important when we request notification). Simple control of this module saves you hours of development. You can start using this project with just two lines of code and easy customization! You can see how I am designed UI and how use pod tutorial on youtube.

Preview GIF loading 4mb. Please, wait

The project is absolutely free, but but it takes time to support and update it. Your support is very motivating and very important. I often receive emails asking me to update or add functionality. Small donate for a cup of coffee helps to develop the project and make it better

Requirements

Swift 4.2. Ready for use on iOS 10+

Integration

Drop in Source/SPPermission folder to your Xcode project. Make sure to enable Copy items if needed and Create groups.

Or via CocoaPods:

pod 'SPPermission'

How to use

Call SPPermission and use func request(). Also passed controller, on which dialog should present:

import UIKit
import SPPermission

class ViewController: UIViewController {

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        SPPermission.Dialog.request(with: [.camera, .microphone, .notification], on: self)
    }
}

If you want to know if permission allowed, you should call the function:

let isAvailableCamera = SPPermission.isAllow(.сamera)

How customize titles and images you can read section DataSource & Customization

Permissions

Also now supported MediaLibrary (Apple Music) permission.

If you want to request notification (or other permissions) without dialog, use the function:

SPPermission.request(.notification, with: {
    //callback
})

Notification permission should be tested only on a real device. If you want to add new permission, create a new issue here

Delegate

To track events hide & allowed permission associated with SPPermission, implement the protocol SPPermissionDialogDelegate:

@objc public protocol SPPermissionDialogDelegate: class {
    
    @objc optional func didHide()
    @objc optional func didAllow(permission: SPPermissionType)
}

And pass the delegate to the function:

SPPermission.Dialog.request(
    with: [.calendar, .microphone],
    on: self,
    delegate: self
)

DataSource & Customization

If you want to change the text, you need to implement the SPPermissionDialogDataSource protocol. Override the needed parameters to see the changes:

@objc public protocol SPPermissionDialogDataSource: class {

    @objc optional var dialogTitle: String { get }
    @objc optional var dialogSubtitle: String { get }
    @objc optional var dialogComment: String { get }
    @objc optional var allowTitle: String { get }
    @objc optional var allowedTitle: String { get }
    @objc optional var bottomComment: String { get }
    @objc optional var showCloseButton: Bool { get }
    @objc optional func name(for permission: SPPermissionType) -> String?
    @objc optional func description(for permission: SPPermissionType) -> String?
    @objc optional func image(for permission: SPPermissionType) -> UIImage?
    @objc optional func deniedTitle(for permission: SPPermissionType) -> String?
    @objc optional func deniedSubtitle(for permission: SPPermissionType) -> String?
    @objc optional var cancelTitle: String { get }
    @objc optional var settingsTitle: String { get }
}

And pass the object to the function:

SPPermission.Dialog.request(
    with: [.photoLibrary, .contacts],
    on: self,
    delegate: self,
    dataSource: self
)

If you want add or remove close button (for close dialog, need swipe it), you need override parametr showCloseButton. How it will look look at the picture below:

In the project you can find an example for usage SPPermissionDialogDataSource

Purpose String in Info.plist

SPPermssion uses many permissions in one library, you need to add some strings to the Info.plist file with the description. List of keys:

  • NSContactsUsageDescription
  • NSCalendarsUsageDescription
  • NSMicrophoneUsageDescription
  • NSAppleMusicUsageDescription
  • NSSpeechRecognitionUsageDescription

Contribution

I will be glad to your participation in the project. If you want to add new permissions, make a pull request. You can ignore adding an icon, I will add it myself. If you find errors in the project, you can create new issue or fix and make a pull request

For Russian-speaking users

Вы можете глянуть туториал на youtube или почитать статью Обновление библиотеки SPPermission, чтобы больше узнать о проекте. Taк же вы можете прочитать статью Получил 1.2K звезд на GitHub с ужасной архитектурой. Как? о первой версии проекта и работе с архитектурой

My projects

Here I would like to offer you my other projects

SPStorkController

I am create SPStorkController. It is modal controller as in mail or Apple music application. Similar animation and transition. You can see example of use controller in app in AppStore

SparrowKit

The SPPermission in the past was part of SparrowKit library. In library you can find many useful extensions & classes. For install via CocoaPods use:

pod 'SparrowKit'

License

SPPermission is released under the MIT license. Check LICENSE.md for details

Contact

If you have any requirements to develop any application or UI, write to me at hello@ivanvorobei.by. I am developing iOS apps and creates designs too. I use swift for developing projects. For requesting more functionality, you should create a new issue. Here are my apps in AppStore: first account & second account