Swift SDK that user request permission for Bluetooth
, Calendar
, Camera
, Contacts
, FaceId
, Health
, Location
, Media Library
, Microphone
, Motion
, Notification
, Photo Library
, Reminders
, Siri
, Speech Recognizer
, Tracking
You need to add some keys to the
Info.plist
file with descriptions, per Apple's requirements. In the header of the permission type you can see the keys.
- iOS 11.0+
- Swift 5.0+
CocoaPods
Add the following line to your Podfile
pod 'OYPermission'
Swift Package Manager
Add OYPermission as a dependency to your Package.swift
and specify OYPermission as a target dependency
import PackageDescription
let package = Package(
name: "YOUR_PROJECT_NAME",
targets: [],
dependencies: [
.package(url: "https://github.com/osmanyildirim/OYPermission", .upToNextMinor(from: "1.0")),
],
targets: [
.target(
name: "YOUR_PROJECT_NAME",
dependencies: ["OYPermission"])
]
)
The settings page of the application can be opened as in the followings.
OYPermission.openSettings(.noPopup) {
/// do stuff
}
OYPermission.openSettings(.withPopup(title: "Title", message: "Message")) {
/// do stuff
}
you need to add
NSBluetoothAlwaysUsageDescription
andNSBluetoothPeripheralUsageDescription
keys and descriptions to Info.plist file for Bluetooth permission request
... request permission of Bluetooth ...
OYPermission.bluetooth.request { granted, error in
/// do stuff
}
... permission status of Bluetooth, returns Status enum value ...
OYPermission.bluetooth.status
... keys that need to be defined in the Info.plist file for the Bluetooth permission request ...
OYPermission.bluetooth.descriptionKeys
you need to add
NSCalendarsUsageDescription
key and description to Info.plist file for Calendar permission request
... request permission of Calendar ...
OYPermission.calendar.request { granted, error in
/// do stuff
}
... permission status of Calendar, returns Status enum value ...
OYPermission.calendar.status
... the key that needs to be defined in the Info.plist file for the Calendar permission request ...
OYPermission.calendar.descriptionKeys
you need to add
NSCameraUsageDescription
key and description to Info.plist file for Camera permission request
... request permission of Camera ...
OYPermission.camera.request { granted, error in
/// do stuff
}
... permission status of Camera, returns Status enum value ...
OYPermission.camera.status
... the key that needs to be defined in the Info.plist file for the Camera permission request ...
OYPermission.camera.descriptionKeys
you need to add
NSContactsUsageDescription
key and description to Info.plist file for Contacts permission request
... request permission of Contacts ...
OYPermission.contacts.request { granted, error in
/// do stuff
}
... permission status of Contacts, returns Status enum value ...
OYPermission.contacts.status
... the key that needs to be defined in the Info.plist file for the Contacts permission request ...
OYPermission.contacts.descriptionKeys
you need to add
NSFaceIDUsageDescription
key and description to Info.plist file for FaceID permission request
... request permission of FaceID ...
OYPermission.faceID.request { granted, error in
/// do stuff
}
... permission status of FaceID, returns Status enum value ...
OYPermission.faceID.status
... the key that needs to be defined in the Info.plist file for the FaceID permission request ...
OYPermission.faceID.descriptionKeys
you need to add
NSHealthUpdateUsageDescription
andNSHealthShareUsageDescription
keys and descriptions to Info.plist file for Health permission request
... request permission of Health ...
let shareTypes: Set<HKSampleType> = [.workoutType()]
let readTypes: Set<HKSampleType> = [.workoutType()]
OYPermission.health.request(shareTypes: shareTypes, readTypes: readTypes) { granted, error in
/// do stuff
}
... permission status of Health with HKObjectType
, returns Status enum value ...
OYPermission.health.status(for: .activitySummaryType())
OYPermission.health.status(for: .workoutType())
... keys that need to be defined in the Info.plist file for the Health permission request ...
OYPermission.health.descriptionKeys
you need to add
NSLocationAlwaysAndWhenInUseUsageDescription
andNSLocationWhenInUseUsageDescription
keys and descriptions to Info.plist file for LocationAlways permission request
... request permission of LocationAlways ...
OYPermission.location(.always).request { granted, error in
/// do stuff
}
... permission status of LocationAlways, returns Status enum value ...
OYPermission.location(.always).status
... keys that need to be defined in the Info.plist file for the LocationAlways permission request ...
OYPermission.location(.always).descriptionKeys
π Tip:
locationStatus
gives status for bothLocationAlways
andLocationWhenInUse
. Can be used together or separately for LocationAlways and LocationWhenInUse.locationStatus returns
.notDetermined
, .authorizedAlways
,.authorizedWhenInUse
and.denied
OYPermission.locationStatus
you need to add
NSLocationAlwaysAndWhenInUseUsageDescription
key and description to Info.plist file for LocationWhenInUse permission request
... request permission of LocationWhenInUse ...
OYPermission.location(.whenInUse).request { granted, error in
/// do stuff
}
... permission status of LocationWhenInUse, returns Status enum value ...
OYPermission.location(.whenInUse).status
... keys that need to be defined in the Info.plist file for the LocationWhenInUse permission request ...
OYPermission.location(.whenInUse).descriptionKeys
π Tip:
locationStatus
gives status for bothLocationAlways
andLocationWhenInUse
. Can be used together or separately for LocationAlways and LocationWhenInUse.locationStatus returns
.notDetermined
, .authorizedAlways
,.authorizedWhenInUse
and.denied
OYPermission.locationStatus
you need to add
NSAppleMusicUsageDescription
key and description to Info.plist file for Media Library permission request
... request permission of Media Library ...
OYPermission.mediaLibrary.request { granted, error in
/// do stuff
}
... permission status of Media Library, returns Status enum value ...
OYPermission.mediaLibrary.status
... the key that needs to be defined in the Info.plist file for the Media Library permission request ...
OYPermission.mediaLibrary.descriptionKeys
you need to add
NSMicrophoneUsageDescription
key and description to Info.plist file for Microphone permission request
... request permission of Microphone ...
OYPermission.microphone.request { granted, error in
/// do stuff
}
... permission status of Microphone, returns Status enum value ...
OYPermission.microphone.status
... the key that needs to be defined in the Info.plist file for the Microphone permission request ...
OYPermission.microphone.descriptionKeys
you need to add
NSMotionUsageDescription
key and description to Info.plist file for Motion permission request
... request permission of Motion ...
OYPermission.motion.request { activities, error in
/// do stuff
}
... permission status of Motion, returns Status enum value ...
OYPermission.motion.status
... the key that needs to be defined in the Info.plist file for the Motion permission request ...
OYPermission.motion.descriptionKeys
you need to add
NSUserNotificationsUsageDescription
key and description to Info.plist file for Notifications permission request
... request permission of Notifications ...
OYPermission.notifications.request { granted, error in
/// do stuff
}
... permission status of Notifications, returns Status enum value ...
OYPermission.notifications.status
... the key that needs to be defined in the Info.plist file for the Notifications permission request ...
OYPermission.notifications.descriptionKeys
you need to add
NSPhotoLibraryAddUsageDescription
key and description to Info.plist file for Photos (Add Only) permission request
... request permission of Photos (Add Only) ...
OYPermission.photos(.addOnly).request { granted, error in
/// do stuff
}
... permission status of Photos (Add Only), returns Status enum value ...
OYPermission.photos(.addOnly).status
... keys that need to be defined in the Info.plist file for the Photos (Add Only) permission request ...
OYPermission.photos(.addOnly).descriptionKeys
you need to add
NSPhotoLibraryAddUsageDescription
andNSPhotoLibraryUsageDescription
keys and descriptions to Info.plist file for Photos (Full Access) permission request
... request permission of Photos (Full Access) ...
OYPermission.photos(.fullAccess).request { granted, error in
/// do stuff
}
... permission status of Photos (Full Access), returns Status enum value ...
OYPermission.photos(.fullAccess).status
... keys that need to be defined in the Info.plist file for the Photos (Full Access) permission request ...
OYPermission.photos(.fullAccess).descriptionKeys
you need to add
NSRemindersUsageDescription
key and description to Info.plist file for Reminders permission request
... request permission of Reminders ...
OYPermission.reminders.request { granted, error in
/// do stuff
}
... permission status of Reminders, returns Status enum value ...
OYPermission.reminders.status
... the key that needs to be defined in the Info.plist file for the Reminders permission request ...
OYPermission.reminders.descriptionKeys
you need to add
NSSiriUsageDescription
key and description to Info.plist file for Siri permission request
... request permission of Siri ...
OYPermission.siri.request { granted, error in
/// do stuff
}
... permission status of Siri, returns Status enum value ...
OYPermission.siri.status
... the key that needs to be defined in the Info.plist file for the Siri permission request ...
OYPermission.siri.descriptionKeys
you need to add
NSSpeechRecognitionUsageDescription
key and description to Info.plist file for Speech Recognition permission request
... request permission of Speech Recognition ...
OYPermission.speechRecognition.request { granted, error in
/// do stuff
}
... permission status of Speech Recognition, returns Status enum value ...
OYPermission.speechRecognition.status
... the key that needs to be defined in the Info.plist file for the Speech Recognition permission request ...
OYPermission.speechRecognition.descriptionKeys
you need to add
NSUserTrackingUsageDescription
key and description to Info.plist file for Tracking permission request
... request permission of Tracking ...
OYPermission.tracking.request { granted, error in
/// do stuff
}
... permission status of Tracking, returns Status enum value ...
OYPermission.tracking.status
... the key that needs to be defined in the Info.plist file for the Tracking permission request ...
OYPermission.tracking.descriptionKeys
enum Status {
/// User grants access
case authorized
/// User grants access to location when in use
case authorizedWhenInUse
/// User grants access to location always
case authorizedAlways
/// User denies access
case denied
/// User has not been asked for access yet
case notDetermined
/// Unsupported this permission
case notSupported
/// Access is restricted by the system
case restrictedBySystem
/// Unknown status of permission
case unknown
}
OYPermission is released under an MIT license. See LICENSE for details.