Runtime permissions

Prompt for camera, location, or contacts before using a gated feature.

Request a permission

Show the native OS permission prompt for one capability. Call it right before you use the feature. permission is one of "camera", "contacts", "record audio", "write to storage", or "location".

The resolved promise tells you the request was sent, not whether the user said yes — read the decision from the next deviceInfo event.

There is no permission-result event. Read the grant/deny outcome from the next deviceInfo event.

import { createBdkNative } from "@bdk/native/browser";

const bdk = createBdkNative();

// Fires the native prompt. The resolved value is a dispatch
// receipt, NOT whether the user granted access.
await bdk.permissions.ask("camera");

Gate a feature behind a permission

Check the current status, prompt only if it isn't granted, then wait for the deviceInfo event to confirm before using the feature. Get the current snapshot from bdk.ready() or bdk.getDeviceInfo(); the deviceInfo event delivers the updated one after the user answers.

Status field names don't match the PermissionName strings:

  • "camera"cameraPermissionStatus
  • "contacts"contactsPermissionStatus
  • "record audio"audiorecordPermissionStatus
  • "write to storage"externalstoragePermissionStatus
  • "location"locationPermissionStatus
import { createBdkNative } from "@bdk/native/browser";

const bdk = createBdkNative();

async function openCamera() {
  const info = await bdk.ready();

  if (info?.cameraPermissionStatus === "granted") {
    bdk.media.capturePhoto();
    return;
  }

  // Ask, then wait for the refreshed deviceInfo to confirm.
  const off = bdk.on("deviceInfo", (next) => {
    if (next.cameraPermissionStatus === "granted") {
      off();
      bdk.media.capturePhoto();
    }
  });

  await bdk.permissions.ask("camera");
}