Parameters
Success Callback Parameters
authSetting Object
Code Example
Basic Usage
Check and Request Permission
Permission Management Page
Related APIs
my.getLocation
Get location
my.chooseImage
Choose image
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Open the Mini Program settings page.
| Property | Type | Required | Description |
|---|---|---|---|
| success | Function | No | Callback on success with current settings |
| fail | Function | No | Callback on failure |
| complete | Function | No | Callback that always executes |
| Property | Type | Description |
|---|---|---|
| authSetting | Object | Results of user authorization. Keys are the values of scopes and values are boolean types, which shows whether the user gives the permission or not. |
| Property | Type | Description |
|---|---|---|
| location | Boolean | Whether location permission (my.getLocation) is granted |
| camera | Boolean | Whether camera permission (my.scan) is granted |
| album | Boolean | Whether photo album permission (my.chooseImage, my.saveImage) is granted |
| userInfo | Boolean | Whether user info permission (my.getOpenUserInfo) is granted |
my.openSetting({
success(res) {
console.log('Current settings:', res.authSetting);
}
});
Page({
async requestLocation() {
my.getLocation({
success: (res) => {
this.handleLocationSuccess(res);
},
fail: (err) => {
// Permission denied, guide user to settings
my.confirm({
title: 'Permission Required',
content: 'Location permission is needed. Would you like to enable it in settings?',
confirmButtonText: 'Open Settings',
success: (result) => {
if (result.confirm) {
my.openSetting({
success: (settingRes) => {
if (settingRes.authSetting.location) {
// Permission granted, try again
this.requestLocation();
}
}
});
}
}
});
}
});
}
});
Page({
data: {
permissions: {}
},
onShow() {
this.loadPermissions();
},
loadPermissions() {
my.openSetting({
success: (res) => {
this.setData({ permissions: res.authSetting });
}
});
},
managePermissions() {
my.openSetting({
success: (res) => {
this.setData({ permissions: res.authSetting });
my.showToast({ content: 'Settings updated' });
}
});
}
});