Skip to main content
Version: v3+

requestPermission

Start from API_LEVEL 3.0 . Please refer to API_LEVEL.

Dynamic permission application, when querying a dynamic permission has not been authorized, you can use this interface to apply for the relevant permission. Generally, before using the system-related functional interface (such as the interface to enable app services), do the relevant permission check and application, otherwise the functional interface will not be allowed to execute due to the permission issue.

Type​

function requestPermission(option: Option): Result

Parameters​

Option​

PropertyTypeRequiredDefaultValueDescriptionAPI_LEVEL
permissionsArray<string>Y-An array of permission strings, with an array length of at least 13.0
callback(result: Array<number>) => voidY-Permission request result callback function3.0

Result​

TypeDescription
numberMethod result value. See 'result' for a description

result​

ValueTypeDescriptionAPI_LEVEL
0numberIn authorization processing, user interaction will be triggered, and the user will be informed of the authorization result in the callback function3.0
1numberThere are no authorization requests that can be made3.0
2numberThe requested interface is authorized and can be called immediately3.0

Example​

import { requestPermission } from '@zos/app'

const result = requestPermission({
permissions: ['device:os.bg_service'],
callback: (result) => {
console.log(result)
},
})
console.log(result)