Request permissions with dialog. You can request many permission at once. Fast start using - type two lines of code. I do UI of dialog in Apple style. Watch how I design UI for this pod on YouTube. If you like the project, do not forget to put star ★
- Requirements
- Installation
- Usage
- Permissions
- DataSource & Customisation
- Delegate
- Purpose String in Info.plist
- How I do UI
- Other Projects +gif
- License
- Contact or Order Develop
Swift 4.2 & 5.0. Ready for use on iOS 10+
CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate SPPermission
into your Xcode project using CocoaPods, specify it in your Podfile
:
pod 'SPPermission'
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate SPPermission
into your Xcode project using Carthage, specify it in your Cartfile
:
github "IvanVorobei/SPPermission"
If you prefer not to use any of the aforementioned dependency managers, you can integrate SPPermission
into your project manually. Put Source/SPPermission
folder in your Xcode project. Make sure to enable Copy items if needed
and Create groups
.
Call SPPermission
and use func request()
. Also, pass the controller on which the 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 is allowed, you need to call the function:
let isAllowedCamera = SPPermission.isAllowed(.camera)
If you want to know if permission is denied, you need to call the function:
let isDeniedMicrophone = SPPermission.isDenied(.microphone)
To learn how to customize titles and images you can read section DataSource & Customisation
If you want to request notification (or other permissions) without dialog, use the function:
SPPermission.request(.notification, with: {
// Callback
})
If you want new permission added, create new issue here.
If you want to change the text, you need to implement SPPermissionDialogDataSource
protocol. Override 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 var dragEnabled: 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 to inhibite drag gesture to discard the dialog view you need to override dragEnabled
parameter, and if you want to add or remove the close button (without the button you’ll have to swipe the dialog to close it), you need to override parameter showCloseButton
. To see what it looks like, see the picture below:
In the project you can find an example of usage of SPPermissionDialogDataSource
If you want to change the color scheme, you need to implement the protocol SPPermissionDialogColorSource
. It is not necessary to override all parameters, you can only change those that are necessary:
@objc public protocol SPPermissionDialogColorSource: class {
@objc optional var whiteColor: UIColor { get }
@objc optional var blackColor: UIColor { get }
@objc optional var baseColor: UIColor { get }
@objc optional var grayColor: UIColor { get }
@objc optional var lightGrayColor: UIColor { get }
@objc optional var iconWhiteColor: UIColor { get }
@objc optional var iconLightColor: UIColor { get }
@objc optional var iconMediumColor: UIColor { get }
@objc optional var iconDarkColor: UIColor { get }
@objc optional var closeIconBackgroundColor: UIColor { get }
@objc optional var closeIconColor: UIColor { get }
}
Will auto check SPPermissionDialogDataSource
also implement SPPermissionDialogColorSource
. You need pass for dataSource
object, which implements two protocols.
To track events of hiding & allowing permissions associated with SPPermission
, implement protocol SPPermissionDialogDelegate
:
@objc public protocol SPPermissionDialogDelegate: class {
@objc optional func didHide()
@objc optional func didAllow(permission: SPPermissionType)
@objc optional func didDenied(permission: SPPermissionType)
}
And pass the delegate to the function:
SPPermission.Dialog.request(
with: [.calendar, .microphone],
on: self,
delegate: self
)
SPPermission uses many permissions in one library; you need to add some strings to the Info.plist
file with description. List of keys:
- NSContactsUsageDescription
- NSCalendarsUsageDescription
- NSMicrophoneUsageDescription
- NSAppleMusicUsageDescription
- NSSpeechRecognitionUsageDescription
- NSMotionUsageDescription
- NSLocationAlwaysUsageDescription
- NSLocationWhenInUseUsageDescription
Do not use the description as the name of the key - this causes errors in the latest version of the new Xcode. Specify For SPPermission
in the description.
If I forgot to mention some, please let me know and create issue or pull request.
I develop SPPermission
in Apple-way. For this, I check 30 apps to get UI-elements for it project. I am take screenshoot and draw it in Sketch. For example, Allow
button is similar to Get
button in the AppStore. Check timelapse to see how I am design SPPermission
:
SPStorkController is very similar to the modal controller displayed in Apple Music, Podcasts and Mail apps. Customizable height of view. Check scroll's bounce for more interactive. Simple adding close button and centering arrow indicator. You can download example Debts - Spending tracker app from AppStore.
If you want to buy source code of this apps, please, go to xcode-shop.com.
Native popup SPAlert is similar to Apple Music or Feedback in AppStore app. Support animations. I tried to repeat Apple alert as much as possible.
You can download example app Debts - Spending tracker from AppStore. If you want to buy source code of example apps, please, go to xcode-shop.com.
SPLarkController make settings screen for your application. You can add buttons and switches. The amount cells is not limited. You can start using project with just two lines of code and easy customisation.
You can download Code - Learn Swift & Design app, which uses SPLarkController
. Also you can buy source code of this app on xcode-shop.com.
If you want buy apps with source code, you can visit my xcode-shop.com. Here I am sale apps, modules, 3D elements and other. In applications you can find many cool UI that will be useful for your projects. Also by buying, you support me and my free GitHub development.
SPPermission
is released under the MIT license. Check LICENSE.md
for details.
If you need any application or UI to be developed, message me at [email protected] or via telegram. I develop iOS apps and designs. I use swift
for development. To request more functionality, you should create a new issue. You can see my apps in AppStore.