Skip to content

Authorization

public classAuthorization

Location permission management — request and monitor authorisation status.

Access via BGGeo.instance.authorization.


Members

getState

public func getState() ->BGGeo.ProviderChangeEvent

Retrieve the current location-services authorization state.

See also - onProviderChange to subscribe to future authorization changes.

let bgGeo = BGGeo.shared
let providerState = bgGeo.authorization.getState()
print("- Provider state:", providerState)

requestPermission

public func requestPermission() async throws -> CLAuthorizationStatus

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+)

let bgGeo = BGGeo.shared

// Listen to onProviderChange to be notified when location authorization changes occur.
let subscription = bgGeo.onProviderChange { event in
    print("[providerchange] \(event)")
}

// First ready the plugin with your configuration.
bgGeo.ready { config in
    config.geolocation.locationAuthorizationRequest = .always
}

// Manually request permission with configured locationAuthorizationRequest.
Task {
    do {
        let status = try await bgGeo.authorization.requestPermission()
        print("[requestPermission] success: \(status)")
    } catch {
        print("[requestPermission] FAILURE: \(error)")
    }
}

requestTemporaryFullAccuracy

public func requestTemporaryFullAccuracy(purpose: String) async throws -> CLAccuracyAuthorization

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

let bgGeo = BGGeo.shared
let subscription = bgGeo.onProviderChange { event in
    if event.accuracyAuthorization == CLAccuracyAuthorization.reducedAccuracy.rawValue {
        Task {
            do {
                let accuracyAuthorization = try await bgGeo.authorization.requestTemporaryFullAccuracy(purpose: "Delivery")
                if accuracyAuthorization == CLAccuracyAuthorization.fullAccuracy.rawValue {
                    print("[requestTemporaryFullAccuracy] GRANTED: \(accuracyAuthorization)")
                } else {
                    print("[requestTemporaryFullAccuracy] DENIED: \(accuracyAuthorization)")
                }
            } catch {
                print("[requestTemporaryFullAccuracy] FAILED TO SHOW DIALOG: \(error)")
            }
        }
    }
}