---
title: "#220: Asking for Access in Style with Permission 🔐"
url: https://littlebitesofcocoa.com/220-asking-for-access-in-style-with-permission
author: Jake Marsh
date: 2016-03-25
published: 2016-03-25
topics: ["Libraries","UIKit"]
description: "Our apps can do tons of useful things with users' data. Before we can though, we must always ask for their permission."
---

# #220: Asking for Access in Style with Permission 🔐

By Jake Marsh, March 25, 2016. HTML: https://littlebitesofcocoa.com/220-asking-for-access-in-style-with-permission

Our **apps** can do tons of useful things with users' **data**. Before we can though, we must always ask for their permission. Whether it's their <i>physical location</i>, <i>photos</i>, or <i>contacts</i>, the user is always in control of when and how we can access their data.

Each of these respective APIs has it's own way of asking the user if they will allow us to access the data within.

Today we'll check out a library called [Permission](https://github.com/delba/Permission) that unifies all of these permission request into one beautiful API. Let's dive in.

We begin by declaring which piece of data we'd like access to:

``` swift
let permission: Permission = .Photos
```

At this point, `permission.status` will report `.NotDetermined` (as we'd expect). Next we'll request the permission, this is what causes the prompt to be presented to the user:

``` swift
permission.request { status in
  switch status {
  case .Authorized:    print("yay!")
  case .Denied:        print("boo")
  case .Disabled:      print("boo boo")
  case .NotDetermined: print("¯\_(ツ)_/¯")
  }
}
```

But wait, there's more!

[Permission](https://github.com/delba/Permission) is smart. If we request access to something the user has already said ‘no' to, it will present an **alert** (with customizable title/message/buttons) that allows the user to jump to the part of **Settings.app** needed to flip the switch back to ‘yes'.

Additionally, [Permission](https://github.com/delba/Permission) also provides a **PermissionSet** type to do this on <i>groups</i> of permissions (i.e. Contacts + Camera + Photos). 

There's also a **PermissionButton** (a **UIButton** subclass) that can display the current permission state, and prompt when tapped.

More info about _Permission_ can be found at [git.io/permission](https://git.io/permission)
