Check and request browser permissions through per-permission delegates.
The SDK sets default delegates for display_notifications and location.
Any other permission resolves not_supported until a delegate is set for
it with setDelegate, which also replaces a default delegate.
Example
const sdk = await UA
// prompt for notifications and register for push if they are granted
const {endingPermission} = await sdk.permissions.requestPermission(
'display_notifications',
true,
true
)
Methods
checkPermissionStatus(permission) → {Promise.<UaPermissionState>|Promise.<UaPermissionState>}
Checks a permission's status without prompting. Resolves not_supported
when no delegate is set for the permission, or when the delegate rejects.
Parameters:
| Name | Type | Description |
|---|---|---|
permission |
Permission
|
the permission |
Returns:
-
- Type:
-
Promise.<UaPermissionState>
the current permission status
-
- Type:
-
Promise.<UaPermissionState>
requestPermission(permission, isUserInteraction, enableAirshipUsageOnGrantopt) → {Promise.<FeatureEnablementResult>|Promise.<FeatureEnablementResult>}
Requests a permission, resolving its status before and after the
request. Resolves not_supported for both when no delegate is set for
the permission, or when the delegate rejects.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
permission |
Permission
|
the permission |
||
isUserInteraction |
boolean
|
whether the request originates from a user gesture |
||
enableAirshipUsageOnGrant |
boolean
|
<optional> |
false |
if the permission is
granted, also enable the Airship features that need it, e.g. registering
for push when |
Returns:
-
- Type:
-
Promise.<FeatureEnablementResult>
the permission status before and after the request
-
- Type:
-
Promise.<FeatureEnablementResult>
setDelegate(permission, delegate) → {Promise.<void>}
Sets a delegate which will be called to check and request the given
permission, replacing any existing delegate for it. Passing undefined
removes it.
Parameters:
| Name | Type | Description |
|---|---|---|
permission |
Permission
|
the permission |
delegate |
PermissionDelegate
|
the delegate |
Returns:
- Type:
-
Promise.<void>
Example
const delegate = {
checkPermissionStatus: async () => myApp.cameraStatus(),
requestPermission: async (isUserInteraction) => {
return myApp.requestCamera(isUserInteraction)
}
}
await sdk.permissions.setDelegate('camera', delegate)