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.
Add the following line to your Podfile
pod 'OYPermission'
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.src="https://raw.github.com/osmanyildirim/OYPermission/main/
],
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
andNSBluetoothPeriphersrc="https://raw.github.com/osmanyildirim/OYPermission/main/geDescription
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
<img style="max-width:100%;" src="Asrc="https://raw.github.com/osmanyildirim/OYPermission/main//Types/calendar.png" width="14" height="14"/> 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.descrsrc="https://raw.github.com/osmanyildirim/OYPermission/main/nKeys
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 fisrc="https://raw.github.com/osmanyildirim/OYPermission/main/r 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 requestsrc="https://raw.github.com/osmanyildirim/OYPermission/main/
OYPermission.location(.always).descriptionKeys
:balloon: 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 LocationWhenInUssrc="https://raw.github.com/osmanyildirim/OYPermission/main/mission 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
:balloon: Tip:
locationStatus
gives status for bothLocationAlways
andLocationWhenInUse
. Can be used together or sepsrc="https://raw.github.com/osmanyildirim/OYPermission/main/ly 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]src="https://raw.github.com/osmanyildirim/OYPermission/main/s://raw.github.com/osmanyildirim/OYPermission/main/#status-enum-type) 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 stasrc="https://raw.github.com/osmanyildirim/OYPermission/main/f 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
/// dosrc="https://raw.github.com/osmanyildirim/OYPermission/main/f
}
... 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 permissionsrc="https://raw.github.com/osmanyildirim/OYPermission/main/otifications ...
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
NSPhotoLibraryUsasrc="https://raw.github.com/osmanyildirim/OYPermission/main/cription
andNSPhotoLibraryAddUsageDescription
keys and descriptions to Info.plist file for Photos permission request
... request permission of Photos ...
OYPermission.photos.request { granted, error in
/// do stuff
}
... permission status of Photos, returns Status enum value ...
OYPermission.photos.status
... keys that need to be defined in the Info.plist file for the Photos permission request ...
OYPermission.photos.descriptionKeys
you need to add
NSRemindersUsageDescription
key and src="https://raw.github.com/osmanyildirim/OYPermission/main/iption 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.
link |
Stars: 0 |
Last commit: 4 weeks ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics