• Stars
    star
    264
  • Rank 155,103 (Top 4 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created about 6 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The convenience wrapper on macOS permissions API, including Mojave Full Disk Access.

PermissionsKit

CI Status Version Carthage Compatible Platform License

Calendar

The convenient wrapper on macOS permissions API.

Current implementation supports permissions for:

Usage

Available types:

typedef NS_ENUM(NSUInteger, MPPermissionType) {
    MPPermissionTypeCalendar = 0,
    MPPermissionTypeReminders,
    MPPermissionTypeContacts,
    MPPermissionTypePhotos,
    MPPermissionTypeFullDiskAccess
} NS_SWIFT_NAME(PermissionType);

Get permissions status:

/**
 * Requests current authorization status for a given type.
 *
 * @discussion It is safe to call this method on system where permission type is not supported. MPAuthorizationStatusAuthorized will be returned.
 *
 * @param permissionType MPPermissionType
 * @return MPAuthorizationStatus
 */
+ (MPAuthorizationStatus)authorizationStatusForPermissionType:(MPPermissionType)permissionType;

Ask for permissions:

/**
 * Requests user authorization for a given permission. Completion will be invoked with a user decision. Completion queue is undefined.
 * @discussion There will be no completion when requesting MPPermissionTypeFullDiskAccess, because its status is unknown. You should implement your own callback mechanism, for example - polling authorization. It is safe to call this method on system where permission type is not supported. MPAuthorizationStatusAuthorized will be returned.
 *
 * @param permissionType MPPermissionType
 * @param completionHandler void (^)(MPAuthorizationStatus status)
 */
+ (void)requestAuthorizationForPermissionType:(MPPermissionType)permissionType withCompletion:(void (^)(MPAuthorizationStatus status))completionHandler;

Calendar

10.9+

Calendar

NSCalendarsUsageDescription key in info.plist is required.

Contacts

10.11+

Contacts

⚠️Uses Private API for calling permissions, because public one is not working properly. See rdar://34158737

NSContactsUsageDescription key is required in Info.plist

Reminders

10.9+

Reminders

NSRemindersUsageDescription key is required in Info.plist

Photos

10.13+

⚠️Works only for Photos Extensions. See rdar://34431396 and rdar://43426722

NSPhotoLibraryUsageDescription key is required in Info.plist

Full Disk Access

10.14+

FDA

Since there is no legal API to request Full Disk Access permissions on macOS 10.14, this is the only workaround to get and ask for it.

⚠️There will be no callback when requesting this type of permission, so you should use your own implementation such as polling permission status, or use other events to handle possible permission change (for example handle NSApp foreground/background status). Calling for permissions opens Preferences->Privacy with selected "Full Disk Access" section.

Application Sandbox:

PermissionsKit can be used in sandboxed applications. It uses multiple files to check for FDA status in case some of the tested files are unaccessible due to reasons unrelated to FDA (not present on older systems, UNIX permissions, etc.) The files are:

  • ~/Library/Safari/Bookmarks.plist
  • ~/Library/Safari/CloudTabs.db
  • /Library/Application Support/com.apple.TCC/TCC.db
  • /Library/Preferences/com.apple.TimeMachine.plist Your app needs to be able to access those files under sandbox. You can do it using Security-Scoped Bookmarks flow(e.g. having a bookmark for root folder), more details in apple documentation Or for testing purposes you can add temporary-exception to your .entitlements file.
<key>com.apple.security.temporary-exception.files.home-relative-path.read-only</key>
<array>
	<string>Library/Safari/Bookmarks.plist</string>
	<string>Library/Safari/CloudTabs.db</string>
</array>
<key>com.apple.security.temporary-exception.files.absolute-path.read-only</key>
<array>
    <string>/Library/Application Support/com.apple.TCC/TCC.db</string>
    <string>/Library/Preferences/com.apple.TimeMachine.plist</string>
</array>

For more details please check Full Disk Access details.

Installation

CocoaPods

PermissionsKit is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'PermissionsKit-macOS'

Carthage

PermissionsKit is available through Carthage. To install it, simple add the following line to your Cartfile:

github "MacPaw/PermissionsKit"

Manual

For manual installation just choose the latest available Release and drag and drop the framework to you project. (You may also need to add it to Embedded Binaries).

Requirements

macOS 10.9+ However different kinds of permissions require different system version it is safe to call for authorization witout actual system check. MPAuthorizationStatusAuthorized will be returned in this case.

Example

See PermissionsKitTestApp target

TestAppScreenshot

Useful links

License

MIT License

Copyright (c) 2018 MacPaw

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

OpenAI

Swift community driven package for OpenAI public API
Swift
1,990
star
2

together-app

πŸ‡ΊπŸ‡¦ A self-hosted app for keeping track of employee wellbeing and dislocation during the Russo-Ukrainian war, with an interactive map.
TypeScript
123
star
3

XADMaster

Objective-C library for archive and file unarchiving and extraction
C
86
star
4

CocoaSprings

Interactive spring animations for macOS/iOS
Swift
75
star
5

ENCryptor

Encryption engine powering Encrypto app
Objective-C
73
star
6

xcsummary

macOS command line tool to parse xcbodebuild test results and generate html output with activity screenshots.
Objective-C
67
star
7

Google-Analytics-for-OS-X

Google Analytics SDK for OS X
Objective-C
51
star
8

symfony-health-check-bundle

Symfony Health Check Bundle Monitoring Project Status
PHP
47
star
9

FMPFeedbackForm

Feedback form for macOS products
Objective-C
43
star
10

Setapp-framework

Setapp Framework
Objective-C
35
star
11

macpaw-ui

UI Kit for MacPaw Web Projects
TypeScript
30
star
12

spm-licenses

Command line tool to collect LICENSE files from SPM dependencies
Swift
29
star
13

sentry-monolog-adapter

Symfony Sentry Monolog Messager Adapter
PHP
27
star
14

Notarized

Tiny tool to reveal notarized applications
Objective-C
23
star
15

behat-messenger-context

Behat Messenger Context
PHP
16
star
16

universal-detector

A Library for character set autodetection
C++
16
star
17

browser-deeplink

JavaScript
14
star
18

binaries-issues

Issues for macosbin.com
13
star
19

eslint-config

JavaScript
8
star
20

Fixel

Fixel font public repository
8
star
21

monolog-gke-formatter

Monolog GKE formatter
PHP
8
star
22

behat-doctrine-fixtures

Behat Doctrine Fixture Context
PHP
7
star
23

k8s-devops-community

Initial templates and manifests for DevOps Community meetup
HCL
7
star
24

behat-redis-context

Redis Context for Behat testing
PHP
6
star
25

local-mirroring-plugin

Composer plugin for monorepo mirroring
PHP
6
star
26

extended_mock_http_client

ExtendedMockHttpClient for Symfony HTTP Client
PHP
6
star
27

behat-api-context

Behat Api Context for Behat testing
PHP
5
star
28

laravel-crowdin-integration

Automate translations uploading/downloading
PHP
5
star
29

behat-http-mock-context

Behat Context Mock HTTP Response in Testing
PHP
4
star
30

AppleNetworkDevice

This repository contains the prototype that demonstrates how to obtain possible Apple device info from local network by given IP address
Swift
4
star
31

msi2021-data-science

3
star
32

sort-resources

Shared resources for waste sorting app
JavaScript
2
star
33

similar-arrays

Library help check is similar arrays you have
PHP
2
star
34

fastlane-plugin-setapp

Ruby
2
star
35

unar

Mono Repo for unar distribution
C
2
star
36

Setapp-SmartSuggestionsSample

This repo contains a sample code for Setapp's Smart Suggestion Initiative.
Swift
2
star
37

behat-nelmio-describer

Bundle for adding sample responses behat test nelmio to api doc
PHP
1
star
38

eslint-config-webservices

[DEPRECATED] Setapp code style rules for Eslint
JavaScript
1
star