TYPE ON THE FIELD BELOW AND PRESS ENTER TO SEARCH FOR BLOG POSTS

Users need to grant permission for an app to access personal information like location, calendar, contact information, reminders, or images. Even though people appreciate the convenience of using an application that has access to information, they also expect to have control over the same. For instance, people like being able to automatically tag photos with their physical location or find nearby friends, but they also want the option to disable such features.

This article is about managing permissions with customizable visual effects. Simple pod saves you hours of development. You can start using this project with just two lines of code and easy customization! In this tutorial, we’re going to focus on just getting started with CocoaPods.

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate FOLDING CELL into your Xcode project using CocoaPods, specify it in your Podfile.

Step 1 : Usage

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)
}
}
  1. If you want to know if permission is allowed, you need to call the function. let isAllowedCamera = SPPermission.isAllowed(.camera)
  2. If you want to know if permission is denied, you need to call the function. let isDeniedMicrophone = SPPermission.isDenied(.microphone)
  3. If you want to request notification (or other permissions) without dialog, use the function. SPPermission.request(.notification, with: {
    // Callback
    })
Step : 2 Delegate

To track events of hiding & allowing permissions associated with SPPermission, implement protocol SPPermissionDialogDelegate and pass the delegate to the function.

@objc public protocol SPPermissionDialogDelegate: class {
@objc optional func didHide()
@objc optional func didAllow(permission: SPPermissionType)
@objc optional func didDenied(permission: SPPermissionType)
}
SPPermission.Dialog.request(
with: [.calendar, .microphone],
on: self,
delegate: self
)
Step : 3 Datasource & Customization

If you want to change the text, you need to implement SPPermissionDialogDataSource protocol. Override needed parameters to see the changes. If you want to inhibit drag gesture to discard the dialog view, you need to override dragEnabled parameter. 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.

@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 }
}
Step : 3 Colors

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

Now that you have a base level understanding, there’s a lot that you can do with SP Permission. SP Permission can help you scale your projects elegantly for app permission. Do let us know your thoughts!

Ready to Build Your Projects?

The best companies and startups hire our top dev teams, and so can you.
Start a Project
GSM Plus Infotech