Skip to content

Authorization

classAuthorization

Location permission management — request and monitor authorisation status.

Access via BGGeo.instance.authorization.


Members

getState

fun getState():ProviderChangeEvent

Retrieve the current location-services authorization state.

See also - onProviderChange to subscribe to future authorization changes.

// Within a coroutine scope
val bgGeo = BGGeo.instance

val providerState = bgGeo.authorization.getState()
Log.d(TAG, "- Provider state: $providerState")

requestPermission

suspend fun requestPermission():PermissionStatus

Manually request location permission using the configured GeolocationConfig.locationAuthorizationRequest.

Resolves successfully if either WhenInUse or Always is granted, regardless of the requested level. Rejects if the user denies.

If permission is already granted, resolves immediately. If iOS has already shown the authorization dialog and the current grant does not match the configured request, the SDK presents an alert offering to direct the user to your app's Settings page.

Note

The SDK automatically requests permission when you call start, startGeofences, or getCurrentPosition. You do not need to call this method in typical use.

See also - GeolocationConfig.locationAuthorizationRequest - GeolocationConfig.disableLocationAuthorizationAlert - GeolocationConfig.locationAuthorizationAlert - AppConfig.backgroundPermissionRationale (Android) - requestTemporaryFullAccuracy (iOS 14+)

// Within a coroutine scope
val bgGeo = BGGeo.instance

try {
    val status = bgGeo.authorization.requestPermission()
    Log.d(TAG, "[requestPermission] success: $status")
} catch (e: Exception) {
    Log.w(TAG, "[requestPermission] FAILURE: $e")
}

requestTemporaryFullAccuracy

suspend fun requestTemporaryFullAccuracy(purpose: String):AccuracyAuthorization

Request temporary full-accuracy location authorization. [iOS 14+]

iOS 14 allows users to grant only reduced location accuracy. This method presents the system dialog (requestTemporaryFullAccuracyAuthorization) requesting full accuracy for the lifetime of the current app session.

Configuration — Info.plist

Add the Privacy - Location Temporary Usage Description Dictionary key to your Info.plist:

The dictionary keys (e.g. Delivery) are passed as purposeKey. The corresponding value is the message shown to the user explaining the purpose of your request.

The dialog fails to present if: - The Info.plist entry for purposeKey is missing. - The app is already authorized for full accuracy. - The app is in the background.

Note

On Android and iOS versions below 14, this method returns AccuracyAuthorization.Full immediately without presenting a dialog.

See also - ProviderChangeEvent.accuracyAuthorization

val bgGeo = BGGeo.instance

bgGeo.onProviderChange { event ->
    if (AccuracyAuthorization.fromValue(event.accuracyAuthorization) == AccuracyAuthorization.REDUCED) {
        try {
            val accuracyAuthorization = kotlinx.coroutines.runBlocking {
                bgGeo.authorization.requestTemporaryFullAccuracy("Delivery")
            }
            if (accuracyAuthorization == AccuracyAuthorization.FULL) {
                Log.d(TAG, "[requestTemporaryFullAccuracy] GRANTED: $accuracyAuthorization")
            } else {
                Log.d(TAG, "[requestTemporaryFullAccuracy] DENIED: $accuracyAuthorization")
            }
        } catch (e: Exception) {
            Log.w(TAG, "[requestTemporaryFullAccuracy] FAILED TO SHOW DIALOG: $e")
        }
    }
}