Simple request permission with native UI and interactive animation
Clone or download
Latest commit 03f198b Dec 10, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Example Add animation to status bar Dec 7, 2018
Source/SPPermission Add animation to status bar Dec 7, 2018
.gitignore removed .DS_Store Nov 18, 2018
LICENSE Initial commit Feb 16, 2017
README.md Update README.md Dec 10, 2018
SPPermission.podspec Update SPPermission.podspec Dec 7, 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'

and import library in class:

import 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?
}

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

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 it on github and simple integrate to your project:

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 need develop application or UI, write me to hello@ivanvorobei.by. I am develop design and ios apps. I am use swift. For request more functionality, you should create a new issue. My apps in AppStore: first account & second account