docs/api/get-system-setting.md
::: sourceCode
GitCode: https://gitcode.com/dcloud/uni-api/tree/alpha/uni_modules/uni-getSystemSetting
GitHub: https://github.com/dcloudio/uni-api/tree/alpha/uni_modules/uni-getSystemSetting
:::
获取系统设置
| Web | 微信小程序 | Android | iOS | HarmonyOS | HarmonyOS(Vapor) |
|---|---|---|---|---|---|
| <a style="color:unset;" href="https://vote.dcloud.net.cn/#/?name=uni-app%20x">x</a> | 4.41 | 3.9 | 4.11 | 4.61 | 5.0 |
| 类型 |
|---|
| GetSystemSettingResult |
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| bluetoothEnabled | boolean | 否 | - | Web: x; 微信小程序: 4.41; Android: 3.9; iOS: 4.11; HarmonyOS: 4.61; HarmonyOS(Vapor): 5.0 | 蓝牙是否开启 |
| bluetoothError | string | 否 | - | Web: x; 微信小程序: 4.41; Android: 3.9; iOS: 4.11; HarmonyOS: 4.61; HarmonyOS(Vapor): 5.0 | 蓝牙的报错信息 |
| locationEnabled | boolean | 是 | - | Web: x; 微信小程序: 4.41; Android: 3.9; iOS: 4.11; HarmonyOS: 4.61; HarmonyOS(Vapor): 5.0 | 位置是否开启 |
| wifiEnabled | boolean | 否 | - | Web: x; 微信小程序: 4.41; Android: 3.9; iOS: 4.11; HarmonyOS: 4.61; HarmonyOS(Vapor): 5.0 | wifi是否开启 |
| wifiError | string | 否 | - | Web: x; 微信小程序: 4.41; Android: 3.9; iOS: x; HarmonyOS: 4.61; HarmonyOS(Vapor): 5.0 | wifi的报错信息 |
| deviceOrientation | string | 是 | - | Web: x; 微信小程序: 4.41; Android: 3.9; iOS: 4.11; HarmonyOS: 4.61; HarmonyOS(Vapor): 5.0 | 设备方向 |
| 合法值 | 兼容性 | 描述 |
|---|---|---|
| portrait | Web: x; 微信小程序: -; Android: -; iOS: -; HarmonyOS: - | 纵向 |
| landscape | Web: x; 微信小程序: -; Android: -; iOS: -; HarmonyOS: - | 横向 |
示例为hello uni-app x alpha分支,与最新HBuilderX Alpha版同步。与最新正式版同步的master分支示例另见
该 API 不支持 Web,请运行 hello uni-app x 到 App 平台体验
::: preview
appRedirect https://hellouniappx.dcloud.net.cn/appredirect.html?path=pages/API/get-system-setting/get-system-setting
<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.bluetoothEnabled" />
</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.locationEnabled" />
</view>
</view>
<view class="uni-list-cell">
<view class="uni-pd">
<view class="uni-label" style="width:180px;">Wi-Fi 的系统开关</view>
</view>
<view class="uni-list-cell-db">
<input type="text" :disabled="true" placeholder="未获取" :value="data.wifiEnabled" />
</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.deviceOrientation" />
</view>
</view>
</view>
<view class="uni-padding-wrap">
<view class="uni-btn-v">
<button type="primary" @tap="getSystemSetting">获取系统设置</button>
</view>
</view>
</view>
</template>
<script setup lang="uts">
type DataType = {
bluetoothEnabled: string;
locationEnabled: string;
wifiEnabled: string;
deviceOrientation: string;
}
const title = ref('getSystemSetting')
const data = reactive({
bluetoothEnabled: "",
locationEnabled: "",
wifiEnabled: "",
deviceOrientation: ""
} as DataType)
const getSystemSetting = () => {
const res = uni.getSystemSetting();
data.bluetoothEnabled = (res.bluetoothEnabled ?? false) ? "开启" : "关闭";
data.locationEnabled = res.locationEnabled ? "开启" : "关闭";
data.wifiEnabled = (res.wifiEnabled ?? false) ? "开启" : "关闭";
data.deviceOrientation = res.deviceOrientation
if (res.bluetoothError != null) {
data.bluetoothEnabled = "无蓝牙权限"
}
if (res.wifiError != null) {
data.wifiEnabled = "无WiFi权限"
}
}
</script>
<style>
.uni-pd {
padding-left: 15px;
}
</style>
:::
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| errMsg | string | 是 | - | Web: -; 微信小程序: 4.41; Android: -; iOS: -; HarmonyOS: - | 错误信息 |