API
Permissions
Access any permission from the permissionsManager instance:
permissions/example.ts
import { permissionsManager } from 'permissions/path'
const cameraPermission = permissionsManager.permissions.camera
A permission provides several useful functions and properties:
A permission uses the @codeleap/store package, meaning it acts as a global state with a persistKey configuration to retain status across user sessions.
name(string): The name of the permission.config(PermissionConfig): The configuration object defined earlier.value(PermissionStatus): The current status of the permission.isGranted(bool): Returns true if the current status is granted or limited.isLimited(bool): Returns true if the current status is limited.isDenied(bool): Returns true if the current status is denied.isBlocked(bool): Returns true if the current status is blocked.set(function): Updates the permission status.use(function): A hook that returns the latest status, automatically updating when the permission value changes anywhere.check(function): Checks the permission status and updates it if different from the current one.request(function): Requests the permission and updates its status if it changes.
Properties
values: An object containing the current status of each permission, with keys as permission names and values as statuses.
Methods
request: Requests a permission, passing through the previously defined requester.
permissions/example.ts
import { permissionsManager } from 'permissions/path'
permissionsManager.request('camera')
check: Checks the status of a permission without needing to access it from the permissions object.
permissions/example.ts
import { permissionsManager } from 'permissions/path'
permissionsManager.check('camera')
requestMany: Requests multiple permissions simultaneously and returns an object with their statuses.
permissions/example.ts
import { permissionsManager } from 'permissions/path'
const result = permissionsManager.requestMany(['camera', 'location'])
console.log(result.camera)
checkMany: Checks multiple permissions at once and returns an object with their statuses.
permissions/example.ts
import { permissionsManager } from 'permissions/path'
const result = permissionsManager.checkMany(['camera', 'location'])
console.log(result.camera)
checkAll: Checks all defined permissions.
This method is called in the
PermissionsManagerconstructor to initially verify the status of all permissions, allowing detection of changes made in the app settings.
permissions/example.ts
import { permissionsManager } from 'permissions/path'
permissionsManager.checkAll()