PermissionsService 0.3.0

PermissionsService 0.3.0

TestsTested
LangLanguage SwiftSwift
License BSD
ReleasedLast Release Aug 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Yuriy Trach, Max Vitruk, Sergiy Loza, OverSwift, Hellen Soloviy.


Downloads

Total961
Week98
Month432

Installs

Apps22
Apps WeekApps This Week 4
Pod Tries1
powered by Segment

GitHub

Stars12
Watchers13
Forks5
Issues0
Contributors5
Pull Requests0

Code

Files18
LOCLines of Code 503


  • By
  • Lemberg Inc

An easy way to do permissions requests & handling automatically.

  1. Why do you need it?
  2. Features
  3. Supported Permission Types
  4. Installation
    1. CocoaPods
    2. Carthage

  5. How To Use
  6. Configurations
    1. Custom alert messages
    2. Location permission

  7. Requirements
  8. Author
  9. License

Why do you need it?

This library is an easy way to handle notDetermined, authorised, restricted and denied cases without doing it by yourself. No more need to do error handling for restricted and denied cases, create and present to user specific alerts. Of cause, it is not a silver bullet, but a good tool for your project!

Features

  • [x] Customise or localise alerts messages via Configuration
  • [x] Automatic alert creating and presenting
  • [x] Opportunity for users to easily change permissions in Settings
  • [x] CoreLocation permission returns you completion block with user’s decision
  • [x] Example project for easy understanding of framework

Supported Permission Types

  • Camera
  • Contacts
  • Calendar Events
  • Gallery
  • Location
  • Media Library
  • Microphone
  • Reminder
  • Siri
  • Speech Recognition

How To Use

  1. Configure your project in all ways needed for chosen permission type. For example, in a case of a gallery, add a specific key to your .plist file.

  2. Implement ServiceDisplay protocol in your class. If it’s not a UIVIewController class you should implement showAlert(_:) method, but if it is - there is a default implementation and you can leave it empty.

  3. Add Permission<T: PermissionService> object with a type you needed and use prepare(_:) method for request permission and presenting alert to the user.

  Permission<Gallery>.prepare(for: self, callback: { (granted) in
      if granted {
          //present library
      } else {
          //perform specific functions 
      }
    })

This case if show a simple variant of use with default permission settings.

Be aware that Calendar permission service named Events.

  1. Enjoy!

Configurations

This library gives you an opportunity to do some customising or configurations if you need it.

Configurate messages

You can add custom alerts messages for denied and restricted cases by creating new struct which conform to ServiceMessages protocol.

struct CameraMessages: ServiceMessages {
    
    let deniedTitle = "Access denied"
    let deniedMessage = "You can enable access to camera in Privacy Settings"
    let restrictedTitle = "Access restricted"
    let restrictedMessage = "Access to camera is restricted"
    
}

To use your custom messages you need to use DefaultConfiguration class. Let’s init it!

   let config = DefaultConfiguration(with: CameraMessages())

And now put it in prepare(_:) method, like this:

  Permission<Camera>.prepare(for: self, with: config) { (granted) in
     if granted {
         print("Granted")
     } else {
         print("Error")
     }

 }

Location permission types

As you can know, you can request two types of user location permission: WhenInUse and Always. For choosing it you need to use configurations too. Class LocationConfiguration is a subclass of DefaultConfiguration and have the same way to use.

You can init it only with type

      let config = LocationConfiguration(.always)

Or you can use it with your messages

     let config = LocationConfiguration(.always, with: CustomLocationMessages())

And then simply put it in your prepare(_:) method as you already did with DefaultConfiguration.

  Permission<Location>.prepare(for: self, with: config) { (granted) in
     if granted {
         print("Granted")
     } else {
         print("Error")
     }

 }

Requirements

Author

Lemberg Solutions

iOS Platform

License

ios-permissions-service is available under the BSD license. See the LICENSE file for more info.