> ## Documentation Index
> Fetch the complete documentation index at: https://docs.radar.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Understand foreground and background location permissions

> Choose the location permission each Radar feature needs on iOS, Android, and the web, request it in the right order, and handle denial, revocation, and active trips.

By the end of this page, you will know which location permission each Radar feature needs, how to request it in a way each platform accepts, and how to keep your app or site working when the user says no.

## Choose permissions by scenario

Request the lowest scope that supports your feature. Foreground means When In Use on iOS, and `ACCESS_FINE_LOCATION` with `ACCESS_COARSE_LOCATION` on Android. Background means Always on iOS, and `ACCESS_BACKGROUND_LOCATION` on Android.

| Scenario | iOS | Android |
| - | - | - |
| App-open use, for example nearby stores or `Radar.trackOnce()` on launch | Foreground. Add `NSLocationWhenInUseUsageDescription` to `Info.plist`. | Foreground. The Radar SDK manifest already declares both permissions. |
| Background geofencing or messaging with `Radar.startTracking()` | Foreground, then background. Add `NSLocationAlwaysAndWhenInUseUsageDescription`, and the Location updates and Background fetch background modes if you use the responsive or continuous preset. | Foreground, then background. Add `ACCESS_BACKGROUND_LOCATION` to your manifest. |
| User-started trip, for example pickup or delivery | Foreground, with the same background modes and the background location indicator. | Foreground, with a location foreground service and its notification. |
| Workforce tracking during a shift | Same as a trip, or background if tracking must start without the worker opening the app. | Same as iOS. |
| Verification with `Radar.trackVerified()` | Foreground. Reduced accuracy can cause a check to fail its accuracy requirement. | Foreground. Approximate location can cause the same failure. |
| Beacons | Foreground to range beacons with `Radar.trackOnce()`. Background to monitor them with `Radar.startTracking()`. | The same, plus Bluetooth permissions, including `BLUETOOTH_SCAN` and `BLUETOOTH_CONNECT` at runtime when you target API level 31 or later. |

Without background access, events are generated only while the app is in use. The web has a single permission and no background access. See [Request location on the web](#request-location-on-the-web).

## Request permissions in order

Request foreground access when the user reaches a location feature. Request background access later, as its own step, and only if a feature needs it. Both platforms deliver the user's choice asynchronously, so start Radar tracking from the callback, not on the line after the request.

```swift Swift theme={null}
import CoreLocation
import RadarSDK

final class LocationPermissionController: NSObject, CLLocationManagerDelegate {
    private let locationManager = CLLocationManager()

    override init() {
        super.init()
        locationManager.delegate = self
    }

    // Call when the user continues from your foreground explanation.
    func requestForeground() {
        if locationManager.authorizationStatus == .notDetermined {
            locationManager.requestWhenInUseAuthorization()
        }
    }

    // Call when the user continues from your background explanation.
    func requestBackground() {
        if locationManager.authorizationStatus == .authorizedWhenInUse {
            locationManager.requestAlwaysAuthorization()
        }
    }

    // Called when the manager is created, when the user answers a prompt,
    // and when the user changes the setting later.
    func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
        switch manager.authorizationStatus {
        case .authorizedAlways:
            Radar.startTracking(trackingOptions: .presetResponsive)
        case .authorizedWhenInUse:
            Radar.trackOnce { status, location, events, user in
                // Update the foreground experience.
            }
        case .denied, .restricted:
            Radar.stopTracking()
            // Show the foreground-only or no-location experience.
        case .notDetermined:
            break
        @unknown default:
            break
        }
    }
}
```

```kotlin Kotlin theme={null}
import android.Manifest
import android.content.pm.PackageManager
import android.os.Build
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import io.radar.sdk.Radar
import io.radar.sdk.RadarTrackingOptions

class MainActivity : AppCompatActivity() {

    private val foregroundRequest = registerForActivityResult(
        ActivityResultContracts.RequestMultiplePermissions()
    ) { grants ->
        val granted = grants[Manifest.permission.ACCESS_FINE_LOCATION] == true ||
            grants[Manifest.permission.ACCESS_COARSE_LOCATION] == true
        if (granted) {
            Radar.trackOnce { status, location, events, user ->
                // Update the foreground experience.
            }
        } else {
            // Show the no-location experience.
        }
    }

    private val backgroundRequest = registerForActivityResult(
        ActivityResultContracts.RequestPermission()
    ) { granted ->
        if (granted) {
            Radar.startTracking(RadarTrackingOptions.RESPONSIVE)
        } else {
            // Keep the foreground-only experience.
        }
    }

    // Call when the user continues from your foreground explanation.
    fun requestForeground() {
        foregroundRequest.launch(
            arrayOf(
                Manifest.permission.ACCESS_FINE_LOCATION,
                Manifest.permission.ACCESS_COARSE_LOCATION
            )
        )
    }

    // Call when the user continues from your background explanation.
    fun requestBackground() {
        val hasForeground = ContextCompat.checkSelfPermission(
            this, Manifest.permission.ACCESS_COARSE_LOCATION
        ) == PackageManager.PERMISSION_GRANTED

        if (hasForeground && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            backgroundRequest.launch(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
        }
    }
}
```

```javascript React Native theme={null}
import Radar from 'react-native-radar';

// Call when the user continues from your foreground explanation.
export async function requestForeground() {
  const status = await Radar.requestPermissions(false);
  return status === 'GRANTED_FOREGROUND' || status === 'GRANTED_BACKGROUND';
}

// Call later, when the user continues from your background explanation.
export async function requestBackground() {
  const status = await Radar.requestPermissions(true);
  return status === 'GRANTED_BACKGROUND';
}
```

```dart Flutter theme={null}
import 'package:flutter_radar/flutter_radar.dart';

// Call when the user continues from your foreground explanation.
Future<bool> requestForeground() async {
  await Radar.requestPermissions(false);
  final status = await Radar.getPermissionsStatus();
  return status == 'GRANTED_FOREGROUND' || status == 'GRANTED_BACKGROUND';
}
```

For the Flutter background request, see [Flutter SDK](https://docs.radar.com/sdk/flutter.md). Both platforms enforce the order:

* **Separate requests**: On iOS, request Always only after When In Use is granted. On Android 11 (API level 30) and later, if you request a foreground permission and `ACCESS_BACKGROUND_LOCATION` in the same call, the system ignores the request and grants neither.
* **Settings on Android**: On Android 11 and later, the background request opens your app's location settings page, where the user chooses **Allow all the time**.
* **Limited prompts**: On iOS, you can ask to upgrade from When In Use to Always one time. On Android 11 and later, after the user selects **Deny** more than once, the system stops showing the dialog. After that, the only path is the system Settings app.

## Request location on the web

A browser has one location permission for each site and no background access, so the web SDK gets a location only while your page is open.

* **The first location call prompts**: There's no separate request method. The browser shows its prompt the first time your page calls a method that reads the device location, such as `Radar.trackOnce()`, or `Radar.fraud.trackVerified()` on the no-download path. Make that call from a user action, such as a button, after your own explanation.
* **HTTPS is required**: Browsers give a location only to pages served over HTTPS, with an exception for `localhost` during development. Inside an iframe, the embedding page must also set `allow="geolocation"` on the frame.
* **A block is remembered**: After the user blocks location for your site, the browser doesn't prompt again, and the call fails with `ERROR_PERMISSIONS` (`RadarPermissionsError`). The user has to allow location in the browser's site settings.
* **The operating system comes first**: Location services must be turned on for the browser in macOS or Windows settings. If they're off, the call fails even when your site is allowed. Desktop browsers estimate location mostly from nearby Wi-Fi networks, so ask the user to keep Wi-Fi on.

Check the current state before you ask, so that you can explain the prompt or show recovery steps:

```javascript theme={null}
const permission = await navigator.permissions.query({ name: 'geolocation' });

if (permission.state === 'denied') {
  // show how to allow location for this site in the browser's settings
} else {
  // 'prompt' or 'granted': explain why you need location, then call from a button click
  try {
    const { user } = await Radar.trackOnce();
  } catch (err) {
    if (err instanceof Radar.errors.RadarPermissionsError) {
      // the user blocked the prompt
    }
  }
}
```

With the Radar Verify companion app, the app gets the location instead of the browser, so the user allows location for Radar Verify in the operating system. See [Choose the companion app or the no-download path](https://docs.radar.com/geo-compliance/verify-location.md#choose-the-companion-app-or-the-no-download-path).

## Explain the request before the system prompt

The system prompt doesn't say why you need location. Show your own screen first, and trigger the system prompt only when the user chooses to continue. A good screen is:

* **Transparent**: It says what location data you collect and how you use it, and links to your privacy policy.
* **Valuable**: It names the feature the user gets, for example pickup timing or nearby offers.
* **Timely**: It appears when the user reaches the feature that needs location, not at first launch.
* **Optional**: It includes a way to decline, and the app keeps working if they do.

Use a separate screen for background access, shown after foreground access is granted. On iOS, the usage description strings in `Info.plist` appear inside the system prompt, so write them for your users.

## Handle denial, restriction, and revocation

Check the current status every time a location feature starts.

| State | What to do |
| - | - |
| Denied, or background declined | Keep the app usable. Show which feature is unavailable, and offer a link to Settings only when the user tries to use it. |
| Restricted on iOS, for example by parental controls | Treat as denied, but don't send the user to Settings. |
| Revoked or downgraded later | Stop tracking that the new status doesn't allow. iOS calls `locationManagerDidChangeAuthorization(_:)`. On Android, check the permission in `onResume()`. |
| Blocked in the browser | Show how to allow location for your site in the browser's site settings. The browser won't prompt again. |
| Approximate location only | Geofence entry and location verification need precise location. Tell the user which feature is limited. |

A tracking or verification call made without location permission returns `ERROR_PERMISSIONS`. Show the no-location experience, and don't retry in a loop.

## Keep an active trip tracking with foreground permission

A user who starts a pickup, delivery, or shift has asked for tracking and can see it happening. Both platforms support this with foreground permission and extra configuration. Start the trip while the app is visible.

> [tab] iOS
>
> 1. In Xcode, under **Signing & Capabilities**, add **Background Modes** and turn on **Location updates** and **Background fetch**.
> 2. Track with the continuous preset, which sets the `showBlueBar` tracking option. iOS then shows the background location indicator while your app uses location in the background.
>
> If the user force quits the app, iOS doesn't relaunch an app that has only When In Use authorization.

> [tab] Android
>
> 1. Use the `CONTINUOUS` preset or set `foregroundServiceEnabled` in your tracking options. The SDK then runs a foreground service with a persistent notification.
> 2. In Android SDK 4.0.0 and later, declare the service and its permission in your app manifest:
>
> ```xml theme={null}
> <manifest xmlns:android="http://schemas.android.com/apk/res/android"
>     xmlns:tools="http://schemas.android.com/tools">
>     <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
>     <application>
>         <service
>             android:name="io.radar.sdk.RadarForegroundService"
>             android:foregroundServiceType="location"
>             tools:targetApi="26" />
>     </application>
> </manifest>
> ```
>
> 3. Declare your foreground service use in the Play Console. Google Play doesn't accept geofencing as a foreground service use case.
>
> If the service isn't declared, the SDK logs an error and tracks without a foreground service. Tracking stops if the user selects **Force stop**.

See [Track pickups, deliveries, and workers](https://docs.radar.com/geofencing/trips.md).

## Know the limits of background tracking

* **Timing**: Background permission doesn't guarantee when the system delivers a location. With the efficient and responsive presets, the SDK wakes up while the user is moving and shuts down when they stop.
* **Terminated apps**: With Always authorization, iOS can relaunch a terminated app only for some update types. See [Tracking options](https://docs.radar.com/sdk/tracking.md). Android keeps delivering after the app is swiped away, but not after **Force stop**.
* **Missed updates**: If the system delivers no update, Radar can't generate a geofence or trip event for that period.

## See permission status for your users

The location permission statistics in the Radar dashboard use four states:

| Dashboard state | iOS `authorizationStatus` | Android | Web |
| - | - | - | - |
| Granted background | `.authorizedAlways` | `ACCESS_BACKGROUND_LOCATION` is granted. | Not applicable |
| Granted foreground | `.authorizedWhenInUse` | Fine or coarse location is granted, and background isn't. | The site is allowed. |
| Denied | `.denied` or `.restricted` | No location permission is granted, and the SDK has seen a foreground permission denied. | The site is blocked. |
| Not determined | `.notDetermined` | None of the above. | The browser hasn't asked yet, or will ask each time. |

## Verify your permission flow

On a physical iPhone and a physical Android device:

1. Fresh install. Confirm that no system prompt appears until you reach a location feature.
2. Grant foreground access. Confirm that the foreground feature works and that background tracking hasn't started.
3. Continue to the background step. Confirm that it is a separate request.
4. Decline background access. Confirm that foreground features still work and the app doesn't ask again on the next launch.
5. Deny access in Settings, then return to the app. Confirm that tracking stops and the app explains which feature is unavailable.
6. Start a trip with foreground access only, lock the device, and move. Confirm that locations arrive in the dashboard.

On the web, in a fresh browser profile:

1. Load the page. Confirm that no browser prompt appears until you start a location feature.
2. Block the prompt. Confirm that the page explains how to allow location, and that it doesn't call again in a loop.
3. Allow location in the site settings and try again. Confirm that the feature works.

## Platform references

* Apple: [Requesting authorization to use location services](https://developer.apple.com/documentation/CoreLocation/requesting-authorization-to-use-location-services)
* Web: [Geolocation API](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API)
* Android: [Request location permissions](https://developer.android.com/develop/sensors-and-location/location/permissions/runtime) and [Request background location](https://developer.android.com/develop/sensors-and-location/location/permissions/background)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.