# uni.getSystemInfo(options)

HBuilderX4.13-alpha版本,uniPlatform属性在 app 平台临时调整过,由 app 改为 app-androidapp-ios,HBuilderX 4.14-alpha版本已回撤此调整。如果开发者使用HBuilderX4.13-alpha版发布项目时使用了uni-id-common、uni-id、uni-id-pages或uni-id-pages-x,则需要分别升级到如下版本来兼容此次临时调整:uni-id@3.3.32、uni-id-common@1.0.17、uni-id-pages@1.1.20、uni-id-pages-x@1.1.1

异步获取系统信息

uni-app 提供了异步(uni.getSystemInfo)和同步(uni.getSystemInfoSync)的2个API获取系统信息。

按照运行环境层级排序,从底层向上,systemInfo有6个概念:

  • device:运行应用的设备,如iphone、huawei
  • os:设备的操作系统,如 ios、andriod、windows、mac、linux
  • rom:基于操作系统的定制,Android系统特有概念,如miui、鸿蒙
  • host:运行应用的宿主程序,即OS和应用之间的运行环境,如浏览器、微信等小程序宿主、集成uniMPSDK的App。uni-app直接开发的app没有host概念
  • uni:uni-app框架相关的信息,如uni-app框架的编译器版本、运行时版本
  • app:开发者的应用相关的信息,如应用名称、版本

因本API涉及的信息越来越多,查询速度会逐渐变慢。由此拆解分出3个新API,uni.getDeviceInfouni.getAppBaseInfouni.getWindowInfo。新API包含的信息更多。

# 参数

名称 类型 必填 默认值 描述
options GetSystemInfoOptions -
名称 类型 必备 默认值 描述
success (result: GetSystemInfoResult) => void | null null 接口调用成功的回调函数
fail (result: UniError) => void | null null 接口调用失败的回调函数
complete (result: any) => void | null null 接口调用结束的回调函数(调用成功、失败都会执行)
# GetSystemInfoResult 的属性值
名称 类型 必备 默认值 描述
SDKVersion string - 客户端基础库版本
appId string - manifest.json 中应用appid。
appLanguage string - 应用设置的语言。
appName string - manifest.json 中应用名称。
appVersion string - manifest.json 中应用版本名称。
appVersionCode string - manifest.json 中应用版本名号。
brand string - 手机品牌。
browserName string - 浏览器名称。App 端是系统 webview 的名字,比如 wkwebview、chrome。小程序端为空
browserVersion string - 浏览器版本、webview 版本。
deviceId string - 设备 ID
deviceBrand string - 设备品牌。如:applehuawei
deviceModel string - 设备型号
deviceType "phone" | "pad" | "tv" | "watch" | "pc" | "undefined" | "car" | "vr" | "appliance" - 设备类型。
devicePixelRatio number - 设备像素比
deviceOrientation "portrait" | "landscape" - 设备方向。
language string - 程序设置的语言
model string - 手机型号
osName "ios" | "android" | "mac" | "windows" | "linux" - 系统名称
osVersion string - 操作系统版本。如 ios 版本,andriod 版本
osLanguage string - 操作系统语言
osTheme "light" | "dark" - 操作系统主题
pixelRatio number - 设备像素比
platform "ios" | "android" | "mac" | "windows" | "linux" - 客户端平台
screenWidth number - 屏幕宽度,单位为px
screenHeight number - 屏幕高度,单位为px
statusBarHeight number - 状态栏的高度,单位为px
system string - 操作系统版本
safeArea SafeArea - 在竖屏正方向下的安全区域
名称 类型 必备 默认值 描述
left number - 安全区域左上角横坐标,单位为px
right number - 安全区域右下角横坐标,单位为px
top number - 安全区域左上角纵坐标,单位为px
bottom number - 安全区域右下角纵坐标,单位为px
width number - 安全区域的宽度,单位为px
height number - 安全区域的高度,单位为px
safeAreaInsets SafeAreaInsets - 在竖屏正方向下的安全区域插入位置
名称 类型 必备 默认值 描述
left number - 安全区域左侧插入位置,单位为px
right number - 安全区域右侧插入位置,单位为px
top number - 安全区顶部插入位置,单位为px
bottom number - 安全区域底部插入位置,单位为px
ua string - 用户标识。小程序端为空
uniCompileVersion string - uni 编译器版本 已废弃,仅为了向下兼容保留
uniCompilerVersion string - uni 编译器版本
uniPlatform "app-android" | "app-ios" | "web" | "mp-weixin" | "mp-alipay" | "mp-baidu" | "mp-toutiao" | "mp-lark" | "mp-qq" | "mp-kuaishou" | "mp-jd" | "mp-360" | "quickapp-webview" | "quickapp-webview-union" | "quickapp-webview-huawei" - uni-app 运行平台。
uniRuntimeVersion string - uni 运行时版本
uniCompileVersionCode number - uni 编译器版本号 已废弃,仅为了向下兼容保留
uniCompilerVersionCode number - uni 编译器版本号
uniRuntimeVersionCode number - uni 运行时版本号
version string - 引擎版本号。已废弃,仅为了向下兼容保留 已废弃,仅为了向下兼容保留
romName string - rom 名称。Android 部分机型获取不到值。iOS 恒为 ios
romVersion string - rom 版本号。Android 部分机型获取不到值。iOS 恒为 ios 版本号
windowWidth number - 可使用窗口宽度,单位为px
windowHeight number - 可使用窗口高度,单位为px
windowTop number - 可使用窗口的顶部位置,单位为px
windowBottom number - 可使用窗口的底部位置,单位为px
osAndroidAPILevel number | null - Android 系统API库的版本。
# GetSystemInfoResult 兼容性
Android iOS web
osTheme 4.11 -
osAndroidAPILevel x -

获取OAID、AndroidID等其他设备信息,见插件市场

# getSystemInfo 兼容性

Android iOS web
3.9 4.11 4.0

# 参见

相关 Bug

# uni.getSystemInfoSync()

同步获取系统信息

# 返回值

类型
GetSystemInfoResult
名称 类型 必备 默认值 描述
SDKVersion string - 客户端基础库版本
appId string - manifest.json 中应用appid。
appLanguage string - 应用设置的语言。
appName string - manifest.json 中应用名称。
appVersion string - manifest.json 中应用版本名称。
appVersionCode string - manifest.json 中应用版本名号。
brand string - 手机品牌。
browserName string - 浏览器名称。App 端是系统 webview 的名字,比如 wkwebview、chrome。小程序端为空
browserVersion string - 浏览器版本、webview 版本。
deviceId string - 设备 ID
deviceBrand string - 设备品牌。如:applehuawei
deviceModel string - 设备型号
deviceType "phone" | "pad" | "tv" | "watch" | "pc" | "null" | "car" | "vr" | "appliance" - 设备类型。
devicePixelRatio number - 设备像素比
deviceOrientation "portrait" | "landscape" - 设备方向。
language string - 程序设置的语言
model string - 手机型号
osName "ios" | "android" | "mac" | "windows" | "linux" - 系统名称
osVersion string - 操作系统版本。如 ios 版本,andriod 版本
osLanguage string - 操作系统语言
osTheme "light" | "dark" - 操作系统主题
pixelRatio number - 设备像素比
platform "ios" | "android" | "mac" | "windows" | "linux" - 客户端平台
screenWidth number - 屏幕宽度,单位为px
screenHeight number - 屏幕高度,单位为px
statusBarHeight number - 状态栏的高度,单位为px
system string - 操作系统版本
safeArea SafeArea - 在竖屏正方向下的安全区域
名称 类型 必备 默认值 描述
left number - 安全区域左上角横坐标,单位为px
right number - 安全区域右下角横坐标,单位为px
top number - 安全区域左上角纵坐标,单位为px
bottom number - 安全区域右下角纵坐标,单位为px
width number - 安全区域的宽度,单位为px
height number - 安全区域的高度,单位为px
safeAreaInsets SafeAreaInsets - 在竖屏正方向下的安全区域插入位置
名称 类型 必备 默认值 描述
left number - 安全区域左侧插入位置,单位为px
right number - 安全区域右侧插入位置,单位为px
top number - 安全区顶部插入位置,单位为px
bottom number - 安全区域底部插入位置,单位为px
ua string - 用户标识。小程序端为空
uniCompileVersion string - uni 编译器版本 已废弃,仅为了向下兼容保留
uniCompilerVersion string - uni 编译器版本
uniPlatform "app-android" | "app-ios" | "web" | "mp-weixin" | "mp-alipay" | "mp-baidu" | "mp-toutiao" | "mp-lark" | "mp-qq" | "mp-kuaishou" | "mp-jd" | "mp-360" | "quickapp-webview" | "quickapp-webview-union" | "quickapp-webview-huawei" - uni-app 运行平台。
uniRuntimeVersion string - uni 运行时版本
uniCompileVersionCode number - uni 编译器版本号 已废弃,仅为了向下兼容保留
uniCompilerVersionCode number - uni 编译器版本号
uniRuntimeVersionCode number - uni 运行时版本号
version string - 引擎版本号。已废弃,仅为了向下兼容保留 已废弃,仅为了向下兼容保留
romName string - rom 名称。Android 部分机型获取不到值。iOS 恒为 ios
romVersion string - rom 版本号。Android 部分机型获取不到值。iOS 恒为 ios 版本号
windowWidth number - 可使用窗口宽度,单位为px
windowHeight number - 可使用窗口高度,单位为px
windowTop number - 可使用窗口的顶部位置,单位为px
windowBottom number - 可使用窗口的底部位置,单位为px
osAndroidAPILevel number | null - Android 系统API库的版本。
# GetSystemInfoResult 兼容性
Android iOS web
osTheme 4.11 -
osAndroidAPILevel x -

# getSystemInfoSync 兼容性

Android iOS web
3.9 4.11 4.0

# 参见

相关 Bug

# 示例

hello uni-app x

Template

Script

<template>
  <!-- #ifdef APP -->
  <scroll-view style="flex: 1">
  <!-- #endif -->
    <view>
      <page-head :title="title"></page-head>
      <view class="uni-common-mt">
        <view class="uni-list">
          <view class="uni-list-cell" v-for="(item, _) in items" style="align-items: center">
            <view class="uni-pd">
              <view class="uni-label" style="width: 180px">{{
                item.label
              }}</view>
            </view>
            <view class="uni-list-cell-db">
              <text style="width: 100%;">{{ item.value == '' ? '未获取' : item.value }}</text>
            </view>
          </view>
        </view>
        <view class="uni-padding-wrap">
          <view class="uni-btn-v">
            <button type="primary" @tap="getSystemInfoSync">
              同步获取设备系统信息
            </button>
            <button type="primary" @tap="getSystemInfo" style="margin-top: 20px;">
              异步获取设备系统信息
            </button>
          </view>
        </view>
      </view>
    </view>
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>


<style>
  .uni-pd {
    padding-left: 15px;
  }
</style>

# 通用类型

# GeneralCallbackResult

名称 类型 必备 默认值 描述
errMsg string - 错误信息