---
title: "Recipe: a capability that asks permission"
description: "A native module that needs the person's permission (location here) is asked for in the app's own UI, read as a fact, and recovered from in the app's own UI."
modificationDate: "2026-11-12"
---

> ## Documentation index
> Fetch the complete documentation index at: https://exact.expo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Recipe: a capability that asks permission

<AgentInstructions>

## Submitting feedback

From the app's directory, read `bun exact.mjs feedback status`. Under `never`, keep no note.
Respect `EXACT_FEEDBACK=0` and do not change the policy.

Otherwise record specific, actionable feedback with:
`bun exact.mjs feedback note "Exact docs: https://exact.expo.dev/recipes/permissions: <what was wrong or missing>"`

The note goes to Expo only as that status allows. Include no secrets or personal data.

</AgentInstructions>

A native module that needs the person's permission (location here) is asked
for, read as a fact and recovered from in the app's own UI. Exact never
answers the platform's prompt (LLP 1133 D7).

```prompt Add a capability that asks permission
Add a capability that needs the person's permission (location here) to the Exact app in this folder. Use https://github.com/expo/exact/blob/main/docs/recipes/permissions.md as the source for each step. The Exact checkout has the same page at docs/recipes/permissions.md.

1. If this folder is not an Exact app (it has no exact.mjs and app.contract), stop and tell me. Find the Exact checkout (the folder with scripts/exact.mjs); if you cannot find it, ask me where it is.
2. If I did not say what the app does with the location, propose it and ask me, and ask whether it needs a precise or an approximate location.
3. Install the module: `bun <exact2>/scripts/exact.mjs add geolocation .`.
4. In app.ts, declare one grant line (`device.geolocation-approximate` or `device.geolocation`, not both) with its purpose key, and add the purpose sentence to `strings/en.json`. Write no platform manifest.
5. In app.contract, read `geolocationStatus()` as a fact, ask only from a person's press, and while the state is `denied` say so and offer Open Settings. Everything that does not need the location keeps working.
6. Add tests in app.test.contract for each state, with the agent's answers the recipe lists: allow (`tap @t allow`), deny, a denied launch with its Settings offer, and a position (`type @t <latitude>,<longitude>`).
7. Follow the platform checks in docs/start-here.md (`bun exact.mjs docs platform checks`) for the targets in the app's AGENTS.md and app.json until they pass. Read the reports, including counted findings; a zero exit code alone does not mean clean. Fix the app, not the test. If a finding stays after three rounds of fixes, or the app had it before you changed anything, record it (step 8) and report it; do not keep trying.
8. When a doc was wrong or missing, or a step needed a workaround, read `bun exact.mjs feedback status`. Under `never`, keep no note. Otherwise record it: `bun exact.mjs feedback note "<what happened>"`, which goes to Expo only as that status says. Do not change the policy; tell me how many notes you kept.
9. Tell me the grant line and purpose you wrote, what the app does in each state, and what the tests and verify reported. `apps/weatherlight` in the Exact checkout is the whole example.
```

1. **Declare** one grant line, and its purpose in the strings table. The build
   derives every platform's manifest from it.

   ```ts
   export const grants = 'device.geolocation-approximate locationPurpose';
   ```

   `strings/en.json`: `{ "locationPurpose": "Shows the weather where you are." }`.
   `device.geolocation` is precise; write one, not both.

2. **Read** the state, a fact: `granted`, `prompt`, `denied` or
   `unknown`, with `available` and `accuracy`.

3. **Ask** from a person's action. While `prompt`, the request shows the
   platform's prompt.

4. **Recover:** while `denied`, say so and offer Settings; the rest keeps
   working. A refused request fails and runs no `then`: read
   `failed(located)` ([error alert](https://exact.expo.dev/recipes/error-alert.md)).

```text
use getCurrentPosition, geolocationStatus, GeolocationPosition, GeolocationStatus from "@exact/geolocation"

component App
  resource location = geolocationStatus() as shape GeolocationStatus else empty()
  mutation located as shape GeolocationPosition then arrived
  action useLocation
    send located = getCurrentPosition(maximumAge=600000, apple.desiredAccuracy="threeKilometers")
  action arrived
    match located
      case some(p)
        lat = p.coords.latitude
      case none
        lat = lat
  action openSettings
    openURL("app-settings:")
  view
    column
      if location.available and location.state != "denied"
        button press=useLocation testId="use-location"
          text "Use my location"
      if location.state == "denied"
        text "Location is off. Turn it on in Settings, or choose a city." testId="location-denied"
        button press=openSettings testId="open-settings"
          text "Open Settings"
```

A module's options are keyword arguments; a platform's own are dotted
(`apple.desiredAccuracy`, `android.quality`); an omitted one is the platform's
default. Data code reads the same names:

```ts
import { watchPosition } from '@exact/geolocation';
const here = await watchPosition({ maximumAge: 600000, apple: { distanceFilter: 5000 } });
```

A resource that read it is asked again when it changes; an error rejects with
`{ code, message }`.

**Under the agent** nothing reaches the platform; the drive answers:

- `--permission geolocation=granted` at launch, or `prefer
  permission.geolocation denied` mid-drive;
- a request while `prompt` waits on a `permission` ticket in `state.pending`:
  `tap @t allow`, `deny` or `cancel`;
- a position with none preferred waits on a `position` ticket: `type @t
  51.5074,-0.1278` (latitude, longitude, accuracy);
- `prefer extension geolocation.watchPosition={"coords":{"latitude":48.8566,"longitude":2.3522}}`
  sets the position, and readers are asked again;
- `state.extensions` lists readers, preferred values and tickets.

`apps/weatherlight` is the whole example.
