From 8c82f0733b6e880ae50bb31cd1763657817c1031 Mon Sep 17 00:00:00 2001 From: MohamedRejeb Date: Tue, 20 Aug 2024 16:03:17 +0100 Subject: [PATCH] Handle PermissionStatus.Denied.shouldShowRationale on iOS --- .../permissions/MutablePermissionState.ios.kt | 2 +- .../permissions/PermissionsUtil.kt | 41 ++++++++--- .../helper/AVCapturePermissionHelper.kt | 25 ++++--- .../helper/BluetoothPermissionHelper.kt | 69 ++++++++----------- .../helper/GalleryPermissionHelper.kt | 29 ++++---- .../LocalNotificationPermissionHelper.kt | 45 +++++++----- .../helper/LocationPermissionHelper.kt | 52 +++++++------- .../permissions/helper/PermissionHelper.kt | 19 +++++ .../RemoteNotificationPermissionHelper.kt | 55 +++++++-------- 9 files changed, 192 insertions(+), 145 deletions(-) diff --git a/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/MutablePermissionState.ios.kt b/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/MutablePermissionState.ios.kt index e3b1dd6..b3a209f 100644 --- a/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/MutablePermissionState.ios.kt +++ b/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/MutablePermissionState.ios.kt @@ -61,7 +61,7 @@ internal class MutablePermissionStateImpl( private val permissionDelegate = permission.getPermissionDelegate() - override var status: PermissionStatus by mutableStateOf(PermissionStatus.Denied(false)) + override var status: PermissionStatus by mutableStateOf(PermissionStatus.Denied(shouldShowRationale = false)) init { refreshPermissionStatus() diff --git a/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/PermissionsUtil.kt b/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/PermissionsUtil.kt index 7d67f2c..4e0f144 100644 --- a/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/PermissionsUtil.kt +++ b/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/PermissionsUtil.kt @@ -13,16 +13,37 @@ import platform.AVFoundation.AVMediaTypeVideo internal fun Permission.getPermissionDelegate(): PermissionHelper { return when (this) { - Permission.Camera -> AVCapturePermissionHelper(AVMediaTypeVideo) - Permission.Gallery -> GalleryPermissionHelper() - Permission.ReadStorage, Permission.WriteStorage, Permission.Call -> GrantedPermissionHelper() - Permission.FineLocation, Permission.CoarseLocation -> LocationPermissionHelper() - Permission.Notification -> LocalNotificationPermissionHelper() - Permission.RemoteNotification -> RemoteNotificationPermissionHelper() - Permission.RecordAudio -> AVCapturePermissionHelper(AVMediaTypeAudio) - Permission.BluetoothLe, Permission.BluetoothScan, - Permission.BluetoothConnect, Permission.BluetoothAdvertise, - -> BluetoothPermissionHelper() + Permission.Camera -> + AVCapturePermissionHelper(AVMediaTypeVideo) + Permission.Gallery -> + GalleryPermissionHelper() + + Permission.ReadStorage, + Permission.WriteStorage, + Permission.Call, + -> + GrantedPermissionHelper() + + Permission.FineLocation, + Permission.CoarseLocation, + -> + LocationPermissionHelper() + + Permission.Notification -> + LocalNotificationPermissionHelper() + + Permission.RemoteNotification -> + RemoteNotificationPermissionHelper() + + Permission.RecordAudio -> + AVCapturePermissionHelper(AVMediaTypeAudio) + + Permission.BluetoothLe, + Permission.BluetoothScan, + Permission.BluetoothConnect, + Permission.BluetoothAdvertise, + -> + BluetoothPermissionHelper() } } diff --git a/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/AVCapturePermissionHelper.kt b/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/AVCapturePermissionHelper.kt index 02fc13f..75f669e 100644 --- a/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/AVCapturePermissionHelper.kt +++ b/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/AVCapturePermissionHelper.kt @@ -4,6 +4,7 @@ import com.mohamedrejeb.calf.permissions.ExperimentalPermissionsApi import com.mohamedrejeb.calf.permissions.PermissionStatus import platform.AVFoundation.AVAuthorizationStatus import platform.AVFoundation.AVAuthorizationStatusAuthorized +import platform.AVFoundation.AVAuthorizationStatusNotDetermined import platform.AVFoundation.AVCaptureDevice import platform.AVFoundation.AVMediaType import platform.AVFoundation.authorizationStatusForMediaType @@ -11,25 +12,31 @@ import platform.AVFoundation.requestAccessForMediaType internal class AVCapturePermissionHelper( private val type: AVMediaType, -): PermissionHelper { +) : PermissionHelper { + @OptIn(ExperimentalPermissionsApi::class) override fun launchPermissionRequest(onPermissionResult: (Boolean) -> Unit) { - val status = getCurrentAuthorizationStatus() - when(status) { - AVAuthorizationStatusAuthorized -> onPermissionResult(true) - else -> { + handlePermissionRequest( + onPermissionResult = onPermissionResult, + launchPermissionRequest = { AVCaptureDevice.requestAccessForMediaType(type) { onPermissionResult(it) } } - } + ) } @OptIn(ExperimentalPermissionsApi::class) override fun getPermissionStatus(onPermissionResult: (PermissionStatus) -> Unit) { val status = getCurrentAuthorizationStatus() - val permissionStatus = when(status) { - AVAuthorizationStatusAuthorized -> PermissionStatus.Granted - else -> PermissionStatus.Denied(false) + val permissionStatus = when (status) { + AVAuthorizationStatusAuthorized -> + PermissionStatus.Granted + + AVAuthorizationStatusNotDetermined -> + PermissionStatus.Denied(shouldShowRationale = true) + + else -> + PermissionStatus.Denied(shouldShowRationale = false) } onPermissionResult(permissionStatus) diff --git a/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/BluetoothPermissionHelper.kt b/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/BluetoothPermissionHelper.kt index 5a8620a..c1c4d3b 100644 --- a/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/BluetoothPermissionHelper.kt +++ b/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/BluetoothPermissionHelper.kt @@ -9,48 +9,24 @@ import platform.CoreBluetooth.CBManager import platform.CoreBluetooth.CBManagerAuthorization import platform.CoreBluetooth.CBManagerAuthorizationAllowedAlways import platform.CoreBluetooth.CBManagerAuthorizationNotDetermined -import platform.CoreBluetooth.CBManagerAuthorizationRestricted -import platform.CoreBluetooth.CBManagerState import platform.CoreBluetooth.CBManagerStatePoweredOn import platform.CoreBluetooth.CBManagerStateUnknown import platform.Foundation.NSSelectorFromString import platform.darwin.NSObject -internal class BluetoothPermissionHelper: PermissionHelper { - @OptIn(ExperimentalForeignApi::class) +internal class BluetoothPermissionHelper : PermissionHelper { + @OptIn(ExperimentalForeignApi::class, ExperimentalPermissionsApi::class) override fun launchPermissionRequest(onPermissionResult: (Boolean) -> Unit) { - val isNotDetermined = - if (CBManager.resolveClassMethod(NSSelectorFromString("authorization"))) { - CBManager.authorization == CBManagerAuthorizationNotDetermined - } else { - CBCentralManager().state == CBManagerStateUnknown + handlePermissionRequest( + onPermissionResult = onPermissionResult, + launchPermissionRequest = { + CBCentralManager(object : NSObject(), CBCentralManagerDelegateProtocol { + override fun centralManagerDidUpdateState(central: CBCentralManager) { + onPermissionResult(central.state == CBManagerStatePoweredOn) + } + }, null) } - - if (isNotDetermined) { - CBCentralManager(object : NSObject(), CBCentralManagerDelegateProtocol { - override fun centralManagerDidUpdateState(central: CBCentralManager) { - handleBluetoothState( - state = central.state, - onPermissionResult = onPermissionResult - ) - } - }, null) - } else { - handleBluetoothState( - state = CBCentralManager().state, - onPermissionResult = onPermissionResult - ) - } - } - - private fun handleBluetoothState( - state: CBManagerState, - onPermissionResult: (Boolean) -> Unit - ) { - when (state) { - CBManagerStatePoweredOn -> onPermissionResult(true) - else -> onPermissionResult(false) - } + ) } @OptIn(ExperimentalForeignApi::class) @@ -59,15 +35,26 @@ internal class BluetoothPermissionHelper: PermissionHelper { if (CBManager.resolveClassMethod(NSSelectorFromString("authorization"))) { val state: CBManagerAuthorization = CBManager.authorization when (state) { - CBManagerAuthorizationAllowedAlways, - CBManagerAuthorizationRestricted -> onPermissionResult(PermissionStatus.Granted) - else -> onPermissionResult(PermissionStatus.Denied(false)) + CBManagerAuthorizationAllowedAlways -> + onPermissionResult(PermissionStatus.Granted) + + CBManagerAuthorizationNotDetermined -> + onPermissionResult(PermissionStatus.Denied(shouldShowRationale = true)) + + else -> + onPermissionResult(PermissionStatus.Denied(shouldShowRationale = false)) } } else { - val state: CBManagerState = CBCentralManager().state + val state = CBCentralManager().state when (state) { - CBManagerStatePoweredOn -> onPermissionResult(PermissionStatus.Granted) - else -> onPermissionResult(PermissionStatus.Denied(false)) + CBManagerStatePoweredOn -> + onPermissionResult(PermissionStatus.Granted) + + CBManagerStateUnknown -> + onPermissionResult(PermissionStatus.Denied(shouldShowRationale = true)) + + else -> + onPermissionResult(PermissionStatus.Denied(shouldShowRationale = false)) } } } diff --git a/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/GalleryPermissionHelper.kt b/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/GalleryPermissionHelper.kt index 6b977ef..143681b 100644 --- a/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/GalleryPermissionHelper.kt +++ b/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/GalleryPermissionHelper.kt @@ -2,33 +2,36 @@ package com.mohamedrejeb.calf.permissions.helper import com.mohamedrejeb.calf.permissions.ExperimentalPermissionsApi import com.mohamedrejeb.calf.permissions.PermissionStatus -import platform.AVFoundation.AVAuthorizationStatusAuthorized import platform.Photos.PHAuthorizationStatus import platform.Photos.PHAuthorizationStatusAuthorized +import platform.Photos.PHAuthorizationStatusNotDetermined import platform.Photos.PHPhotoLibrary internal class GalleryPermissionHelper : PermissionHelper { + @OptIn(ExperimentalPermissionsApi::class) override fun launchPermissionRequest(onPermissionResult: (Boolean) -> Unit) { - val status = getCurrentAuthorizationStatus() - when(status) { - AVAuthorizationStatusAuthorized -> onPermissionResult(true) - else -> { + handlePermissionRequest( + onPermissionResult = onPermissionResult, + launchPermissionRequest = { PHPhotoLibrary.requestAuthorization { - when (it) { - PHAuthorizationStatusAuthorized -> onPermissionResult(true) - else -> onPermissionResult(false) - } + onPermissionResult(it == PHAuthorizationStatusAuthorized) } } - } + ) } @OptIn(ExperimentalPermissionsApi::class) override fun getPermissionStatus(onPermissionResult: (PermissionStatus) -> Unit) { val status = getCurrentAuthorizationStatus() - val permissionStatus = when(status) { - PHAuthorizationStatusAuthorized -> PermissionStatus.Granted - else -> PermissionStatus.Denied(false) + val permissionStatus = when (status) { + PHAuthorizationStatusAuthorized -> + PermissionStatus.Granted + + PHAuthorizationStatusNotDetermined -> + PermissionStatus.Denied(shouldShowRationale = true) + + else -> + PermissionStatus.Denied(shouldShowRationale = false) } onPermissionResult(permissionStatus) } diff --git a/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/LocalNotificationPermissionHelper.kt b/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/LocalNotificationPermissionHelper.kt index d87914e..7d7c777 100644 --- a/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/LocalNotificationPermissionHelper.kt +++ b/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/LocalNotificationPermissionHelper.kt @@ -13,40 +13,47 @@ import platform.UserNotifications.UNUserNotificationCenter internal class LocalNotificationPermissionHelper : PermissionHelper { + @OptIn(ExperimentalPermissionsApi::class) override fun launchPermissionRequest(onPermissionResult: (Boolean) -> Unit) { - val notificationCenter = UNUserNotificationCenter.currentNotificationCenter() - - notificationCenter.getNotificationSettingsWithCompletionHandler { settings -> - when (settings?.authorizationStatus) { - UNAuthorizationStatusAuthorized, - UNAuthorizationStatusProvisional, - UNAuthorizationStatusEphemeral -> onPermissionResult(true) - UNAuthorizationStatusNotDetermined -> { - notificationCenter.requestAuthorizationWithOptions( - UNAuthorizationOptionSound.or(UNAuthorizationOptionAlert).or(UNAuthorizationOptionBadge) + handlePermissionRequest( + onPermissionResult = onPermissionResult, + launchPermissionRequest = { + getCurrentNotificationCenter() + .requestAuthorizationWithOptions( + UNAuthorizationOptionSound + .or(UNAuthorizationOptionAlert) + .or(UNAuthorizationOptionBadge) ) { isOk, error -> - if (isOk && error == null) { + if (isOk && error == null) onPermissionResult(true) - } else { + else onPermissionResult(false) - } } - } - else -> onPermissionResult(false) } - } + ) } @ExperimentalPermissionsApi override fun getPermissionStatus(onPermissionResult: (PermissionStatus) -> Unit) { - val notificationCenter = UNUserNotificationCenter.currentNotificationCenter() + val notificationCenter = getCurrentNotificationCenter() notificationCenter.getNotificationSettingsWithCompletionHandler { settings -> when (settings?.authorizationStatus) { UNAuthorizationStatusAuthorized, UNAuthorizationStatusProvisional, - UNAuthorizationStatusEphemeral -> onPermissionResult(PermissionStatus.Granted) - else -> onPermissionResult(PermissionStatus.Denied(false)) + UNAuthorizationStatusEphemeral, + -> + onPermissionResult(PermissionStatus.Granted) + + UNAuthorizationStatusNotDetermined -> + onPermissionResult(PermissionStatus.Denied(shouldShowRationale = true)) + + else -> + onPermissionResult(PermissionStatus.Denied(shouldShowRationale = false)) } } } + + private fun getCurrentNotificationCenter(): UNUserNotificationCenter { + return UNUserNotificationCenter.currentNotificationCenter() + } } \ No newline at end of file diff --git a/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/LocationPermissionHelper.kt b/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/LocationPermissionHelper.kt index 0625962..0d7cb1e 100644 --- a/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/LocationPermissionHelper.kt +++ b/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/LocationPermissionHelper.kt @@ -5,12 +5,13 @@ import com.mohamedrejeb.calf.permissions.PermissionStatus import platform.CoreLocation.CLAuthorizationStatus import platform.CoreLocation.CLLocationManager import platform.CoreLocation.CLLocationManagerDelegateProtocol +import platform.CoreLocation.kCLAuthorizationStatusAuthorized import platform.CoreLocation.kCLAuthorizationStatusAuthorizedAlways import platform.CoreLocation.kCLAuthorizationStatusAuthorizedWhenInUse import platform.CoreLocation.kCLAuthorizationStatusNotDetermined import platform.darwin.NSObject -internal class LocationPermissionHelper: PermissionHelper { +internal class LocationPermissionHelper : PermissionHelper { private var onPermissionResult: ((Boolean) -> Unit)? = null private val manager = CLLocationManager() private val managerDelegate = LocationManagerDelegate { @@ -22,51 +23,56 @@ internal class LocationPermissionHelper: PermissionHelper { manager.delegate = managerDelegate } + @OptIn(ExperimentalPermissionsApi::class) override fun launchPermissionRequest(onPermissionResult: (Boolean) -> Unit) { - val status = getCurrentAuthorizationStatus() - - when(status) { - kCLAuthorizationStatusAuthorizedAlways, - kCLAuthorizationStatusAuthorizedWhenInUse -> onPermissionResult(true) - - kCLAuthorizationStatusNotDetermined -> { + handlePermissionRequest( + onPermissionResult = onPermissionResult, + launchPermissionRequest = { this.onPermissionResult = onPermissionResult manager.requestWhenInUseAuthorization() } - - else -> onPermissionResult(false) - } + ) } @ExperimentalPermissionsApi override fun getPermissionStatus(onPermissionResult: (PermissionStatus) -> Unit) { val status = getCurrentAuthorizationStatus() - val permissionStatus = when(status) { + val permissionStatus = when (status) { + kCLAuthorizationStatusAuthorized, kCLAuthorizationStatusAuthorizedAlways, - kCLAuthorizationStatusAuthorizedWhenInUse -> PermissionStatus.Granted + kCLAuthorizationStatusAuthorizedWhenInUse, + -> + PermissionStatus.Granted - else -> PermissionStatus.Denied(false) + kCLAuthorizationStatusNotDetermined -> + PermissionStatus.Denied(shouldShowRationale = true) + + else -> + PermissionStatus.Denied(shouldShowRationale = false) } onPermissionResult(permissionStatus) } - private fun getCurrentAuthorizationStatus(): CLAuthorizationStatus { - return CLLocationManager.authorizationStatus() - } + private fun getCurrentAuthorizationStatus(): CLAuthorizationStatus = + CLLocationManager.authorizationStatus() } private class LocationManagerDelegate( - private val onPermissionResult: (Boolean) -> Unit -): NSObject(), CLLocationManagerDelegateProtocol { + private val onPermissionResult: (Boolean) -> Unit, +) : NSObject(), CLLocationManagerDelegateProtocol { override fun locationManager( manager: CLLocationManager, - didChangeAuthorizationStatus: CLAuthorizationStatus + didChangeAuthorizationStatus: CLAuthorizationStatus, ) { - when(didChangeAuthorizationStatus) { + when (didChangeAuthorizationStatus) { + kCLAuthorizationStatusAuthorized, kCLAuthorizationStatusAuthorizedAlways, - kCLAuthorizationStatusAuthorizedWhenInUse -> onPermissionResult(true) + kCLAuthorizationStatusAuthorizedWhenInUse, + -> + onPermissionResult(true) - else -> onPermissionResult(false) + else -> + onPermissionResult(false) } } } \ No newline at end of file diff --git a/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/PermissionHelper.kt b/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/PermissionHelper.kt index 4518188..3ec9170 100644 --- a/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/PermissionHelper.kt +++ b/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/PermissionHelper.kt @@ -10,4 +10,23 @@ internal interface PermissionHelper { fun getPermissionStatus( onPermissionResult: (PermissionStatus) -> Unit ) +} + +@OptIn(ExperimentalPermissionsApi::class) +internal fun PermissionHelper.handlePermissionRequest( + onPermissionResult: (Boolean) -> Unit, + launchPermissionRequest: () -> Unit, +) { + getPermissionStatus { status -> + when (status) { + is PermissionStatus.Granted -> + onPermissionResult(true) + + is PermissionStatus.Denied -> + if (status.shouldShowRationale) + launchPermissionRequest() + else + onPermissionResult(false) + } + } } \ No newline at end of file diff --git a/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/RemoteNotificationPermissionHelper.kt b/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/RemoteNotificationPermissionHelper.kt index 13a6465..a945ed1 100644 --- a/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/RemoteNotificationPermissionHelper.kt +++ b/calf-permissions/src/iosMain/kotlin/com.mohamedrejeb.calf/permissions/helper/RemoteNotificationPermissionHelper.kt @@ -2,9 +2,6 @@ package com.mohamedrejeb.calf.permissions.helper import com.mohamedrejeb.calf.permissions.ExperimentalPermissionsApi import com.mohamedrejeb.calf.permissions.PermissionStatus -import platform.CoreLocation.kCLAuthorizationStatusAuthorizedAlways -import platform.CoreLocation.kCLAuthorizationStatusAuthorizedWhenInUse -import platform.CoreLocation.kCLAuthorizationStatusNotDetermined import platform.UserNotifications.UNAuthorizationOptionAlert import platform.UserNotifications.UNAuthorizationOptionBadge import platform.UserNotifications.UNAuthorizationOptionSound @@ -14,33 +11,26 @@ import platform.UserNotifications.UNAuthorizationStatusNotDetermined import platform.UserNotifications.UNAuthorizationStatusProvisional import platform.UserNotifications.UNUserNotificationCenter -internal class RemoteNotificationPermissionHelper: PermissionHelper { +internal class RemoteNotificationPermissionHelper : PermissionHelper { + @OptIn(ExperimentalPermissionsApi::class) override fun launchPermissionRequest(onPermissionResult: (Boolean) -> Unit) { - val notificationCenter = getCurrentNotificationCenter() - - notificationCenter.getNotificationSettingsWithCompletionHandler { settings -> - when (settings?.authorizationStatus) { - UNAuthorizationStatusAuthorized, - UNAuthorizationStatusProvisional, - UNAuthorizationStatusEphemeral -> onPermissionResult(true) - UNAuthorizationStatusNotDetermined -> { - getCurrentNotificationCenter() - .requestAuthorizationWithOptions( - UNAuthorizationOptionSound - .or(UNAuthorizationOptionAlert) - .or(UNAuthorizationOptionBadge) - ) { isOk, error -> - if (isOk && error == null) { - onPermissionResult(true) - } else { - onPermissionResult(false) - } - } - } - else -> onPermissionResult(false) + handlePermissionRequest( + onPermissionResult = onPermissionResult, + launchPermissionRequest = { + getCurrentNotificationCenter() + .requestAuthorizationWithOptions( + UNAuthorizationOptionSound + .or(UNAuthorizationOptionAlert) + .or(UNAuthorizationOptionBadge) + ) { isOk, error -> + if (isOk && error == null) + onPermissionResult(true) + else + onPermissionResult(false) + } } - } + ) } @ExperimentalPermissionsApi @@ -50,8 +40,15 @@ internal class RemoteNotificationPermissionHelper: PermissionHelper { when (settings?.authorizationStatus) { UNAuthorizationStatusAuthorized, UNAuthorizationStatusProvisional, - UNAuthorizationStatusEphemeral -> onPermissionResult(PermissionStatus.Granted) - else -> onPermissionResult(PermissionStatus.Denied(false)) + UNAuthorizationStatusEphemeral, + -> + onPermissionResult(PermissionStatus.Granted) + + UNAuthorizationStatusNotDetermined -> + onPermissionResult(PermissionStatus.Denied(shouldShowRationale = true)) + + else -> + onPermissionResult(PermissionStatus.Denied(shouldShowRationale = false)) } } }