uni.getSystemInfo(options)
HBuilderX4.13-alpha版本,uniPlatform属性在 app 平台临时调整过,由 app
改为 app-android
、app-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.getDeviceInfo、uni.getAppBaseInfo、uni.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 | 是 | - | 设备品牌。如:apple 、huawei 。 |
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 | 是 | - | 设备品牌。如:apple 、huawei 。 | 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
通用类型
GeneralCallbackResult
名称 | 类型 | 必备 | 默认值 | 描述 |
errMsg | string | 是 | - | 错误信息 |