The convenient wrapper on macOS permissions API.
Current implementation supports permissions for:
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;
10.9+
NSCalendarsUsageDescription
key in info.plist is required.
10.11+
NSContactsUsageDescription
key is required in Info.plist
10.9+
NSRemindersUsageDescription
key is required in Info.plist
10.13+
NSPhotoLibraryUsageDescription
key is required in Info.plist
10.14+
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.
NSApp
foreground/background status).
Calling for permissions opens Preferences->Privacy with selected "Full Disk Access" section.
PermissionsKit can be used in sandboxed applications. But this application should have access to the file
Library/Safari/Bookmarks.plist
on 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.
PermissionsKit is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'PermissionsKit-macOS'
PermissionsKit is available through Carthage. To install it, simple add the following line to your Cartfile:
github "MacPaw/PermissionsKit"
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).
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.
See PermissionsKitTestApp target
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.