Home

Awesome

<p align="center"> <img src="https://github.com/ennioma/arek/blob/master/code/Assets/arek.png" alt="AREK" width="295" height="54"> </p> <br />

Platform Version Pod Version Carthage compatible License Swift Version

AREK is a clean and easy to use wrapper over any kind of iOS permission written in Swift.

Why AREK could help you building a better app is well described by Apple <a href="https://developer.apple.com/ios/human-interface-guidelines/interaction/requesting-permission/">here</a>:

Request personal data only when your app clearly needs it.
...
Explain why your app needs the information if it’s not obvious.
...
Request permission at launch only when necessary for your app to function.
...

Every goal could be easily reached using AREK.

🚨 AREK is a Swift 4.2 and Xcode 10 compatible project 🚨

Important!

Build Status

BranchStatus
MasterBuddyBuild
DevelopBuddyBuild

Table of Contents

  1. Implemented permissions
  2. How to use AREK
  3. Permissions Configuration
  4. How to install AREK
  5. How to contribute
  6. TODO
  7. License and Credits

<a name="implementedPermissions"></a>

Implemented permissions

<a name="howTo"></a>

How to use AREK

Check permission status

    let permission = ArekPhoto()

    permission.status { (status) in
        switch status {
        case .authorized:
            print("! βœ… !")
        case .denied:
            print("! ⛔️ !" )
        case .notDetermined:
            print("! πŸ€” !" )
        case .notAvailable:
            print("! 🚫 !" )
        }
    }

Request a permission

    let permission = ArekEvent()

    permission.manage { (status) in
        switch status {
        case .authorized:
            symbol = "βœ…"
        case .denied:
            symbol = "⛔️"
        case .notDetermined:
            symbol = "πŸ€”"
        case .notAvailable:
            return "🚫"
        }
    }

<a name="permissionsConfiguration"></a>

Permissions Configuration

General configuration

Each permission type included in AREK is configurable through the ArekConfiguration struct. Each permission has a default configuration, so if you are happy with the basic configuration you don't have to care about how it works behind the scenes.

An ArekConfiguration is made up by:

frequency: ArekPermissionFrequency (.Always, .EveryHour, .OnceADay, .OnceAWeek, .JustOnce) This frequency value is related to how often you want to the user to re-enable a permission if that one has been disallowed.

Set by default to .OnceADay


presentInitialPopup: Bool This is an initial popup used to ask kindly to the user to allow a permission. This is useful to avoid burning the possibility to show the system popup.

Set by default to true


presentReEnablePopup: Bool This is the popup used to kindly to the user to re-enable that permission. The frequency value is related to this popup.

Set by defaul to true

Configure the initial and the re-enable popup: ArekPopupData

ArekPopupData is the struct used to configure both the pre-permission popup and the re-enable popup. These popups could be instances of the amazing PMAlertController by Codeido or native iOS alerts.

The configuration is the following:

public struct ArekPopupData {
    var title: String!
    var message: String!
    var image: String!
    var type: ArekPopupType!

    public init(title: String = "", message: String = "", image: String = "", type: ArekPopupType = .codeido) {
        self.title = title
        self.message = message
        self.image = image
        self.type = type
    }
}

This is an example of the ArekContacts pre-enable popup using PMAlertController: <br /> <img src="https://github.com/ennioma/arek/blob/master/code/Assets/arek_contacts.png" width="150">

If you want to present a native UIAlertController set the type to .native otherwise if you want to setup a PMAlertController set the type to .codeido.

Localized Strings

AREK by convention expects to find localized strings in your Localizable files in order to configure the UI.

In the following table there are the configurations for:

Messages related to the iOS native permission popup should be configured following the conventions described <a href="https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW1">here</a>.

PermissionPre-permission TitlePre-permission MessageRe-Enable TitleRe-Enable MessageImageAllow Button TitleDeny Button Title
CameraArekCamera_initial_titleArekCamera_initial_messageArekCamera_reenable_titleArekCamera_reenable_messageArekCamera_imageArekCamera_allow_button_titleArekCamera_deny_button_title
CloudKitArekCloudKit_initial_titleArekCloudKit_initial_messageArekCloudKit_reenable_titleArekCloudKit_reenable_messageArekCloudKit_imageArekCloudKit_allow_button_titleArekCloudKit_deny_button_title
ContactsArekContacts_initial_titleArekContacts_initial_messageArekContacts_reenable_titleArekContacts_reenable_messageArekContacts_imageArekContacts_allow_button_titleArekContacts_deny_button_title
EventsArekEvents_initial_titleArekEvents_initial_messageArekEvents_reenable_titleArekEvents_reenable_messageArekEvents_imageArekEvents_allow_button_titleArekEvents_deny_button_title
HealthKitArekHealth_initial_titleArekHealth_initial_messageArekHealth_reenable_titleArekHealth_reenable_messageArekHealth_imageArekHealth_allow_button_titleArekHealth_deny_button_title
Media LibraryArekMediaLibrary_initial_titleArekMediaLibrary_initial_messageArekMediaLibrary_reenable_titleArekMediaLibrary_reenable_messageArekMediaLibrary_imageArekMediaLibrary_allow_button_titleArekMediaLibrary_deny_button_title
MicrophoneArekMicrophone_initial_titleArekMicrophone_initial_messageArekMicrophone_reenable_titleArekMicrophone_reenable_messageArekMicrophone_imageArekMicrophone_allow_button_titleArekMicrophone_deny_button_title
MotionArekMotion_initial_titleArekMotion_initial_messageArekMotion_reenable_titleArekMotion_reenable_messageArekMotion_imageArekMotion_allow_button_titleArekMotion_deny_button_title
NotificationsArekNotifications_initial_titleArekNotifications_initial_messageArekNotifications_reenable_titleArekNotifications_reenable_messageArekNotifications_imageArekNotifications_allow_button_titleArekNotifications_deny_button_title
Photo LibraryArekPhoto_initial_titleArekPhoto_initial_messageArekPhoto_reenable_titleArekPhoto_reenable_messageArekPhoto_imageArekPhoto_allow_button_titleArekPhoto_deny_button_title
RemindersArekReminders_initial_titleArekReminders_initial_messageArekReminders_reenable_titleArekReminders_reenable_messageArekReminders_imageArekReminders_allow_button_titleArekReminders_ deny_button_title
SiriArekSiri_initial_titleArekSiri_initial_messageArekSiri_reenable_titleArekSiri_reenable_messageArekSiri_imageArekSiri_allow_button_titleArekSiri_deny_button_title
Speech RecognizerArekSpeechRecognizer_initial_titleArekSpeechRecognizer_initial_messageArekSpeechRecognizer_reenable_titleArekSpeechRecognizer_reenable_messageArekSpeechRecognizer_imageArekSpeechRecognizer_allow_button_titleArekSpeechRecognizer_deny_button_title
BluetoothArekBluetooth_initial_titleArekBluetooth_initial_messageArekBluetooth_reenable_titleArekBluetooth_reenable_messageArekBluetooth_imageArekBluetooth_allow_button_titleArekBluetooth_deny_button_title
LocationArekBaseLocation_initial_titleArekBaseLocation_initial_messageArekBaseLocation_reenable_titleArekBaseLocation_reenable_messageArekBaseLocation_imageArekBaseLocation_allow_button_titleArekBaseLocation_deny_button_title

<a name="howToInstall"></a>

How to install AREK

CocoaPods

Add AREK to your Podfile

use_frameworks!
target 'MyTarget' do
    pod 'arek', '~> 2.0.2'
end

If you want to install just a specific permission, let's say Bluetooth, you have to specify:

use_frameworks!
target 'MyTarget' do
    pod 'arek/Bluetooth', '~> 2.0.2'
end
$ pod install

Carthage

github "ennioma/arek" ~> "2.0.2"

Then on your application target Build Phases settings tab, add a "New Run Script Phase". Create a Run Script with the following content:

/usr/local/bin/carthage copy-frameworks

and add the following paths under "Input Files":

$(SRCROOT)/Carthage/Build/iOS/arek.framework
$(SRCROOT)/Carthage/Build/iOS/PMAlertController.framework

Swift Package Manager

import PackageDescription

let package = Package(
  name: "YourApp",
  dependencies: [
    .Package(url: "https://github.com/ennioma/arek.git", versionMajor: 2, minor: 0)
  ]
)

Add AREK source code to your project

Add https://github.com/ennioma/arek/tree/master/arek/arek/Arek folder to your project.

πŸ™ Take care about adding the ArekHealth class to your project. It includes HealthKit in your project, so if you do this without using HealthKit, your app will be rejected during the AppStore review.

<a name="contribute"></a>

How to contribute

Contributions are welcome πŸ™Œ If you'd like to improve this projects I've shared with the community, just open an issue or raise a PR from the current develop branch.

For any information or request feel free to contact me on twitter (@ennioma).

<a name="todo"></a>

TODO

<a name="licenseCredits"></a>

License and Credits

License:

AREK is available under the MIT license. See the LICENSE file for more info.

Arek on the Web:

  1. This week in Swift - Natasha The Robot
  2. iOS Dev Weekly - Dave Verwer

Credits:

Icones provided by Freepik and Vectors Market from Flaticon