Requests user authorization for device-related JavaScript APIs listed in the Scope list. Prompts the user to grant permission without calling the target API. If already authorized, skips the prompt and invokes the success callback directly.
Request parameters
|
Parameter |
Type |
Required |
Description |
|
scope |
String |
Yes |
Permission scope to request. |
|
success |
Function |
No |
Callback invoked on successful authorization. |
|
fail |
Function |
No |
Callback invoked on failed authorization. |
Scope list
|
Scope |
Description |
APIs |
|
location |
Geographical location |
|
|
camera |
Camera |
|
|
bluetooth |
Bluetooth |
All methods of WVBluetooth |
|
album |
Album |
|
|
contacts |
Contacts |
All methods of WVContacts |
|
microphone |
Microphone |
|
|
file |
File |
All methods of WVFile, WVImage.saveImage, WVVideo.saveVideoToPhotosAlbum |
|
call |
Phone call |
|
|
vibrate |
Vibration |
|
|
screen |
Screen capture |
Response parameters
The success callback receives an object with these attributes:
|
Attribute |
Type |
Description |
|
successScope |
JSONObject |
Scopes the user authorized. |
|
msg |
String |
Error message on failure. |
The fail callback receives an object with the error in msg:
|
Error message |
Description |
Solution |
|
You need to configure the authorization switch to apply for authorization |
Authorization switch is not enabled. |
Verify the authorization switch is configured during container initialization. |
|
Parameter parsing exception |
Request parameters cannot be parsed. |
Verify request parameter format. |
|
Authorization scope cannot be empty |
The |
Check the |
|
User not bound |
The |
Verify container user information includes a |
|
User refuses authorization request |
The user denied the authorization request. |
Prompt the user with a clear reason to grant authorization. |
|
The authorization you requested does not exist. Please check the parameters |
The provided |
Verify the |
Sample code
window.WindVane.call('wv', 'getSetting', {}, function(res) {
if (!res.authSetting['location']) {
window.WindVane.call('wv', 'authorize', {scope: 'location'}, function(res) {
if (res.successScope['location']) {
alert('success authorize location');
// Call the required JavaScript API.
}
}, function(e) {
alert('failure:' + JSON.stringify(e));
})
} else {
alert('success authorize location');
}
}, function(e) {
alert('failure:' + JSON.stringify(e));
});