简体中文
获取 APP 授权设置。
| Web | 微信小程序 | Android | iOS | HarmonyOS | HarmonyOS(Vapor) |
|---|---|---|---|---|---|
| x | 4.41 | 3.9 | 4.11 | 4.61 | 5.0 |
| 类型 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| GetAppAuthorizeSettingResult | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
示例为hello uni-app x alpha分支,与最新HBuilderX Alpha版同步。与最新正式版同步的master分支示例另见
该 API 不支持 Web,请运行 hello uni-app x 到 App 平台体验
<template>
<page-head :title="title"></page-head>
<view class="uni-common-mt">
<view class="uni-list">
<view class="uni-list-cell">
<view class="uni-pd">
<view class="uni-label" style="width:180px;">是否授权使用相册</view>
</view>
<view class="uni-list-cell-db">
<input type="text" :disabled="true" placeholder="未获取" :value="data.albumAuthorized" />
</view>
</view>
<view class="uni-list-cell">
<view class="uni-pd">
<view class="uni-label" style="width:180px;">是否授权使用蓝牙</view>
</view>
<view class="uni-list-cell-db">
<input type="text" :disabled="true" placeholder="未获取" :value="data.bluetoothAuthorized" />
</view>
</view>
<view class="uni-list-cell">
<view class="uni-pd">
<view class="uni-label" style="width:180px;">是否授权使用摄像头</view>
</view>
<view class="uni-list-cell-db">
<input type="text" :disabled="true" placeholder="未获取" :value="data.cameraAuthorized" />
</view>
</view>
<view class="uni-list-cell">
<view class="uni-pd">
<view class="uni-label" style="width:180px;">是否授权使用定位</view>
</view>
<view class="uni-list-cell-db">
<input type="text" :disabled="true" placeholder="未获取" :value="data.locationAuthorized" />
</view>
</view>
<view class="uni-list-cell">
<view class="uni-pd">
<view class="uni-label" style="width:180px;">定位准确度</view>
</view>
<view class="uni-list-cell-db">
<input type="text" :disabled="true" placeholder="未获取" :value="data.locationAccuracy" />
</view>
</view>
<view class="uni-list-cell">
<view class="uni-pd">
<view class="uni-label" style="width:180px;">是否授权使用麦克风</view>
</view>
<view class="uni-list-cell-db">
<input type="text" :disabled="true" placeholder="未获取" :value="data.microphoneAuthorized" />
</view>
</view>
<view class="uni-list-cell">
<view class="uni-pd">
<view class="uni-label" style="width:180px;">是否授权通知</view>
</view>
<view class="uni-list-cell-db">
<input type="text" :disabled="true" placeholder="未获取" :value="data.notificationAuthorized" />
</view>
</view>
<!-- #ifdef APP-IOS -->
<view class="uni-list-cell">
<view class="uni-pd">
<view class="uni-label" style="width:180px;">是否允许通知带有提醒</view>
</view>
<view class="uni-list-cell-db">
<input type="text" :disabled="true" placeholder="未获取" :value="data.notificationAlertAuthorized" />
</view>
</view>
<view class="uni-list-cell">
<view class="uni-pd">
<view class="uni-label" style="width:180px;">是否允许通知带有标记</view>
</view>
<view class="uni-list-cell-db">
<input type="text" :disabled="true" placeholder="未获取" :value="data.notificationBadgeAuthorized" />
</view>
</view>
<view class="uni-list-cell">
<view class="uni-pd">
<view class="uni-label" style="width:180px;">是否允许通知带有声音</view>
</view>
<view class="uni-list-cell-db">
<input type="text" :disabled="true" placeholder="未获取" :value="data.notificationSoundAuthorized" />
</view>
</view>
<!-- #endif -->
</view>
<view class="uni-padding-wrap">
<view class="uni-btn-v">
<button type="primary" @tap="getAppAuthorizeSetting">获取App授权设置</button>
</view>
</view>
</view>
</template>
<script setup lang="uts">
type DataType = {
cameraAuthorized: string;
albumAuthorized: string;
locationAuthorized: string;
locationAccuracy: string;
microphoneAuthorized: string;
bluetoothAuthorized: string;
notificationAuthorized: string;
notificationAlertAuthorized: string;
notificationBadgeAuthorized: string;
notificationSoundAuthorized: string;
}
const title = ref('getAppAuthorizeSetting')
const data = reactive({
cameraAuthorized: "",
albumAuthorized: "",
locationAuthorized: "",
locationAccuracy: "",
microphoneAuthorized: "",
bluetoothAuthorized: "",
notificationAuthorized: "",
notificationAlertAuthorized: "",
notificationBadgeAuthorized: "",
notificationSoundAuthorized: ""
} as DataType)
const getAppAuthorizeSetting = () => {
const res = uni.getAppAuthorizeSetting();
data.albumAuthorized = res.albumAuthorized;
data.bluetoothAuthorized = res.bluetoothAuthorized;
data.cameraAuthorized = res.cameraAuthorized;
data.locationAuthorized = res.locationAuthorized;
data.locationAccuracy = res.locationAccuracy ?? "unsupported";
data.microphoneAuthorized = res.microphoneAuthorized;
data.notificationAuthorized = res.notificationAuthorized;
// #ifdef APP-IOS
data.notificationAlertAuthorized = res.notificationAlertAuthorized;
data.notificationBadgeAuthorized = res.notificationBadgeAuthorized;
data.notificationSoundAuthorized = res.notificationSoundAuthorized;
// #endif
}
</script>
<style>
.uni-pd {
padding-left: 15px;
}
</style>
如需跳转到权限设置界面,参考uni.openAppAuthorizeSetting
注意:
Android和iOS的权限设计并不相同,比如iOS有相册权限,而Android不同版本的相册权限逻辑不一样,低版本没有单独的相册权限,归入本地文件读写权限(非沙盒文件),高版本又独立出来。还有很多权限只有一个平台才有。
权限的命名各平台也不相同,所以本API返回的权限名称不是Android和iOS原始的命名,只是一个示意名称。
本API只返回部分权限,Android平台的权限非常多,在Android上获取所有未授权权限,另见UTSAndroid.getSystemPermissionDenied,这里的权限名称就是Android原始的权限名称了。
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| errMsg | string | 是 | - | 错误信息 |