PermissionsKit-macOS

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

Showing:

Popularity

Downloads/wk

0

GitHub Stars

188

Maintenance

Last Commit

6mos ago

Contributors

11

Package

Dependencies

0

License

MIT

Categories

Readme

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. But this application should have access to the file Library/Safari/Bookmarks.pliston macOS 10.14 and Library/Safari/CloudTabs.db on macOS 10.15. You can do it using Security-Scoped Bookmarks flow, 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>

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

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.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100