has.authorize(Object object)
Requests user authorization. After the API is called, a dialog box will be displayed immediately, asking the user to authorize the atomic service to use a feature or acquire user data. However, it will not actually call the corresponding API to use the feature or acquire the data. If the user has already granted the requested permissions, a success message will be returned without displaying the dialog box.
Since: 1.0.0
Parameters
Parameters are included in an object, which are described in the table below.
Name | Type | Mandatory | Description |
|---|---|---|---|
scope | string | Yes | Scope of the permissions to request. |
success | function | No | Callback to be invoked when the API call is successful. |
fail | function | No | Callback to be invoked when the API call fails. |
complete | function | No | Callback to be invoked when the API call is complete, regardless of success or failure. |
The permissions to request must have been declared in the project configuration file. Otherwise, the authorization will fail. For details, see Declaring Permissions.
Example
has.authorize({
scope: 'scope.userLocation',
success: (res) => {
console.log(`authorize success, res = ${JSON.stringify(res)}`);
},
fail: (err) => {
console.log(`authorize fail, err = ${JSON.stringify(err)}`);
},
complete: (res) => {
console.log(`authorize complete, res = ${JSON.stringify(res)}`);
}
});