Dala.Permissions (dala v0.3.1)

Copy Markdown View Source

Permission management for Dala plugins.

Provides a unified interface for requesting and checking permissions across iOS and Android. Maps permission atoms to platform-specific permission strings and handles runtime request flows.

Supported Permissions

  • :camera — Camera access
  • :microphone — Microphone access
  • :bluetooth — Bluetooth access
  • :location — Location services
  • :storage — File/storage access
  • :photos — Photo library access
  • :contacts — Contacts access
  • :notifications — Push notifications
  • :nfc — NFC tag reading

Usage

# Request a permission at runtime — pass the screen pid
# The result arrives as {:permission_result, permission, result} via handle_info/2
Dala.Permissions.request(self(), :camera)

# Check if a permission is granted
Dala.Permissions.check(:camera)

# Get all supported permissions
Dala.Permissions.supported_permissions()

Summary

Functions

Returns the Android permission string.

Checks if a permission is currently granted. Returns :granted or :denied.

Returns the iOS plist key for a permission.

Returns the platform-specific permission string.

Requests a permission from the OS.

Checks if a permission is supported.

Returns all supported permissions.

Validates permissions, returning :ok or {:error, {:unsupported, [permissions]}}.

Types

permission()

@type permission() ::
  :camera
  | :microphone
  | :bluetooth
  | :location
  | :storage
  | :photos
  | :contacts
  | :notifications
  | :nfc

Functions

android_permission(arg1)

@spec android_permission(permission()) :: String.t() | nil

Returns the Android permission string.

check(permission)

@spec check(permission()) :: :granted | :denied

Checks if a permission is currently granted. Returns :granted or :denied.

ios_plist_key(arg1)

@spec ios_plist_key(permission()) :: String.t() | nil

Returns the iOS plist key for a permission.

permission_string(atom)

@spec permission_string(permission()) :: String.t()

Returns the platform-specific permission string.

request(pid, permission)

@spec request(pid(), permission()) :: :ok | {:error, term()}

Requests a permission from the OS.

pid is the process that will receive the result message {:permission_result, permission, result} — typically the screen process (self()).

Returns :ok immediately; the actual permission result arrives asynchronously via the pid's mailbox.

supported?(permission)

@spec supported?(permission()) :: boolean()

Checks if a permission is supported.

supported_permissions()

@spec supported_permissions() :: [permission()]

Returns all supported permissions.

validate_permissions(permissions)

@spec validate_permissions([permission()]) :: :ok | {:error, term()}

Validates permissions, returning :ok or {:error, {:unsupported, [permissions]}}.