Object “permission”

Object > NativeObject > Permission

Allows to request runtime permissions which are required to access certain device features. Trying to access a Tabris.js API without a required permission will throw an Error.

A permission can be either a category (supported on Android and iOS) or a specific Android permission name.

See the permissions documentation for full details on how to handle runtime permissions.

Constructor private
Singleton permission
Namespace tabris
Direct subclasses None
JSX support No

Example

import {permission} from 'tabris';

if (permission.isAuthorized('camera')) {
  console.log('Camera permission is available');
} else {
  (async () => {
    const status = await permission.requestAuthorization('camera');
    console.log(`Camera permission has been ${status}.`);
  })();
}

See also:

JSX Simple approach to check and request permissions
TSX Full featured example with multiple permissions and states

Methods

getAuthorizationStatus(…permissions)

Checks the authorization status for a given set of permissions.

Since an app permission can change during the apps lifecycle or when it is changed in the app settings, it is recommended to check the permissions status before making API calls that require a granted permission.

Parameter Type Optional Description
…permissions string[] No A list of permissions to get the authorization status for.

Returns string

isAuthorizationPossible(…permissions)

Checks if any of the given permissions allow to request authorization. A permission is regarded as allowed to authorize when its status is either 'undetermined' or 'declined'.

Parameter Type Optional Description
…permissions string[] No A list of permissions to check if authorization is possible.

Returns boolean

isAuthorized(…permissions)

Checks whether the given set of permissions is authorized. A set of permissions is regarded as authorized when the status of all permissions is 'granted'.

Parameter Type Optional Description
…permissions string[] No A list of permissions to check its authorization status.

Returns boolean

requestAuthorization(…permissions)

Request authorization for a set of permissions.

If any of the permissions allow to request authorization, the method call will prompt the user to grant the permission and returns the result in the resolved promise. If the status can not be changed, the current status is returned by the resolved promise.

Parameter Type Optional Description
…permissions string[] No A list of permissions to request authorization for.

Returns Promise<string>

withAuthorization(permissions, onAuthorized, onUnauthorized, onError)

Tries to authorize access to the given permissions, either by already holding the permissions or by requesting authorization for the given permissions. When the result is 'granted' the onAuthorized callback will be invoked. If any other state is determined the onUnauthorized callback will be invoked. In case of an Error the onError` callback will be invoked.

Parameter Type Optional Description
permissions string | string[] No An individual permission or a list of permissions to gain authorization for.
onAuthorized Function No A callback to be invoked if the desired permissions could be granted. The permissions will have the status 'granted’.
onUnauthorized Function No A callback to be invoked when the desired permissions could not be granted.
onError Function No A callback to be invoked if the request failed.

Returns void