# 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" | "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 为操作系统版本号(同 osVersion)。
windowWidth number - 可使用窗口宽度,单位为px
windowHeight number - 可使用窗口高度,单位为px
windowTop number - 内容区域距离顶部的距离(同CSS变量 --window-top),单位为px
windowBottom number - 内容区域距离底部的距离(同CSS变量 --window-bottom),单位为px
osAndroidAPILevel number | null - Android 系统API库的版本。
# SafeArea 兼容性
Android iOS web
left 3.9 4.11 -
right 3.9 4.11 -
top 3.9 4.11 -
bottom 3.9 4.11 -
width 3.9 4.11 -
height 3.9 4.11 -
# SafeAreaInsets 兼容性
Android iOS web
left 3.9 4.11 -
right 3.9 4.11 -
top 3.9 4.11 -
bottom 3.9 4.11 -
# GetSystemInfoResult 兼容性
Android iOS web
SDKVersion 3.9 4.11 -
appId 3.9 4.11 -
appLanguage 3.9 4.11 -
appName 3.9 4.11 -
appVersion 3.9 4.11 -
appVersionCode 3.9 4.11 -
brand 3.9 4.11 -
browserName 3.9 4.11 -
browserVersion 3.9 4.11 -
deviceId 3.9 4.11 -
deviceBrand 3.9 4.11 -
deviceModel 3.9 4.11 -
deviceType 3.9 4.11 -
devicePixelRatio 3.9 4.11 -
deviceOrientation 3.9 4.11 -
language 3.9 4.11 -
model 3.9 4.11 -
osName 3.9 4.11 -
osVersion 3.9 4.11 -
osLanguage 3.9 4.11 -
osTheme 4.11 -
pixelRatio 3.9 4.11 -
platform 3.9 4.11 -
screenWidth 3.9 4.11 -
screenHeight 3.9 4.11 -
statusBarHeight 3.9 4.11 -
system 3.9 4.11 -
safeArea 3.9 4.11 -
safeAreaInsets 3.9 4.11 -
ua 3.9 4.11 -
uniCompileVersion 3.9 4.11 -
uniCompilerVersion 3.9 4.11 -
uniPlatform 3.9 4.11 -
uniRuntimeVersion 3.9 4.11 -
uniCompileVersionCode 3.9 4.11 -
uniCompilerVersionCode 3.9 4.11 -
uniRuntimeVersionCode 3.9 4.11 -
version 3.9 4.11 -
romName 3.9 4.11 -
romVersion 3.9 4.11 -
windowWidth 3.9 4.11 -
windowHeight 3.9 4.11 -
windowTop 3.9 4.11 -
windowBottom 3.9 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" | "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 为操作系统版本号(同 osVersion)。
windowWidth number - 可使用窗口宽度,单位为px
windowHeight number - 可使用窗口高度,单位为px
windowTop number - 内容区域距离顶部的距离(同CSS变量 --window-top),单位为px
windowBottom number - 内容区域距离底部的距离(同CSS变量 --window-bottom),单位为px
osAndroidAPILevel number | null - Android 系统API库的版本。
# SafeArea 兼容性
Android iOS web
left 3.9 4.11 -
right 3.9 4.11 -
top 3.9 4.11 -
bottom 3.9 4.11 -
width 3.9 4.11 -
height 3.9 4.11 -
# SafeAreaInsets 兼容性
Android iOS web
left 3.9 4.11 -
right 3.9 4.11 -
top 3.9 4.11 -
bottom 3.9 4.11 -
# GetSystemInfoResult 兼容性
Android iOS web
SDKVersion 3.9 4.11 -
appId 3.9 4.11 -
appLanguage 3.9 4.11 -
appName 3.9 4.11 -
appVersion 3.9 4.11 -
appVersionCode 3.9 4.11 -
brand 3.9 4.11 -
browserName 3.9 4.11 -
browserVersion 3.9 4.11 -
deviceId 3.9 4.11 -
deviceBrand 3.9 4.11 -
deviceModel 3.9 4.11 -
deviceType 3.9 4.11 -
devicePixelRatio 3.9 4.11 -
deviceOrientation 3.9 4.11 -
language 3.9 4.11 -
model 3.9 4.11 -
osName 3.9 4.11 -
osVersion 3.9 4.11 -
osLanguage 3.9 4.11 -
osTheme 4.11 -
pixelRatio 3.9 4.11 -
platform 3.9 4.11 -
screenWidth 3.9 4.11 -
screenHeight 3.9 4.11 -
statusBarHeight 3.9 4.11 -
system 3.9 4.11 -
safeArea 3.9 4.11 -
safeAreaInsets 3.9 4.11 -
ua 3.9 4.11 -
uniCompileVersion 3.9 4.11 -
uniCompilerVersion 3.9 4.11 -
uniPlatform 3.9 4.11 -
uniRuntimeVersion 3.9 4.11 -
uniCompileVersionCode 3.9 4.11 -
uniCompilerVersionCode 3.9 4.11 -
uniRuntimeVersionCode 3.9 4.11 -
version 3.9 4.11 -
romName 3.9 4.11 -
romVersion 3.9 4.11 -
windowWidth 3.9 4.11 -
windowHeight 3.9 4.11 -
windowTop 3.9 4.11 -
windowBottom 3.9 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 - 错误信息