Skip to main content

getPermission

Returns the current status of a given permission — allowed, denied, or notDetermined. Use this before calling any permission-gated API to avoid unnecessary failures.

Signature

import { getPermission } from '@apps-in-toss/web-framework';

declare function getPermission(permission: {
name: PermissionName;
access: PermissionAccess;
}): Promise<PermissionStatus>;

type PermissionName = 'camera' | 'photos' | 'contacts' | 'geolocation' | 'microphone' | 'clipboard';
type PermissionAccess = 'read' | 'write' | 'access';
type PermissionStatus = 'notDetermined' | 'denied' | 'allowed';

Parameters

NameTypeRequiredDescription
permission.namePermissionNameThe permission to check. One of 'camera' / 'photos' / 'contacts' / 'geolocation' / 'microphone' / 'clipboard'.
permission.accessPermissionAccessThe access type being requested. One of 'read' / 'write' / 'access'.

Returns

  • Promise<PermissionStatus> — current permission status:
    • 'allowed' — user has granted access.
    • 'denied' — user or OS has blocked access. Calling the gated API in this state throws.
    • 'notDetermined' — user hasn't decided yet. Default on first launch.

Permission

getPermission itself requires no permission — it queries the permission state. For the full check → prompt → invoke flow used with other APIs, see Guides — Permissions pattern.

Examples

Minimal

import { getPermission } from '@apps-in-toss/web-framework';

const status = await getPermission({ name: 'camera', access: 'read' });
console.log('Camera permission:', status);
// 'allowed' | 'denied' | 'notDetermined'

Realistic — check → prompt → invoke

import { getPermission, openPermissionDialog, openCamera } from '@apps-in-toss/web-framework';

async function takePicture() {
// 1. Check current status first.
const status = await getPermission({ name: 'camera', access: 'read' });

if (status === 'denied') {
// 2. Denied — re-prompting has no effect. Guide the user to OS settings.
showAppToast('Camera access was denied. Enable it in Settings → Toss → Permissions.');
return;
}

if (status === 'notDetermined') {
// 3. Not yet decided — show the system dialog.
const result = await openPermissionDialog({ name: 'camera', access: 'read' });
if (result === 'denied') {
showAppToast('Camera permission is required to take a photo.');
return;
}
}

// 4. Guaranteed to be allowed — safe to call the gated API.
const photo = await openCamera({ type: 'photo' });
console.log('Photo captured:', photo);
}

// `showAppToast` is NOT provided by the SDK — substitute your app's own
// toast / snackbar component.
declare function showAppToast(message: string): void;

Realistic — show status badge on mount

import { getPermission, type PermissionStatus } from '@apps-in-toss/web-framework';
import { useEffect, useState } from 'react';

function CameraPermissionBadge() {
const [status, setStatus] = useState<PermissionStatus | null>(null);

useEffect(() => {
getPermission({ name: 'camera', access: 'read' })
.then(setStatus)
.catch(console.error);
}, []);

if (status === null) return <span>Checking…</span>;
if (status === 'allowed') return <span>Camera: allowed</span>;
if (status === 'denied') return <span>Camera: denied</span>;
return <span>Camera: not determined</span>;
}

Try it live

Run getPermission on the Permissions page in sdk-example and inspect the result.

Open in sdk-example

External references