# 系统信息的概念

本 API 在微信小程序上使用会产生警告,请使用 uni.getSystemSetting、uni.getAppAuthorizeSetting、uni.getDeviceInfo、uni.getWindowInfo、uni.getAppBaseInfo 代替

uni-app provides two asynchronous (uni.getSystemInfo) and synchronous (uni.getSystemInfoSync) APIs to obtain system information.

System information returns a lot of content, and each operating system, each MiniApp, and each browser have different definitions of them. These concepts are reorganized in uni-app, and the original concepts of these platforms are also retained for backward compatibility, but it is not recommended to use.

Sorted according to the level of the operating environment, from the bottom up, uni-app has 6 concepts:

  • device:运行应用的设备,如iphone、huawei
  • os:设备的操作系统,如 ios、android、windows、mac、linux、harmonyos(OpenHarmony)
  • rom: customization based on the operating system, unique concepts of the Android system, such as miui, Hongmeng
  • host: The host program that runs the application, that is, the operating environment between the OS and the application, such as the browser, WeChat and other MiniApp hosts, and the App integrated with uniMPSDK. The app directly developed by uni-app has no host concept
  • uni: Information related to the uni-app framework, such as the compiler version and runtime version of the uni-app framework
  • app: developer's application-related information, such as application name, version

# uni.getSystemInfo(OBJECT)

Get system information asynchronously

# getSystemInfo 兼容性

HarmonyOS
HBuilderX 4.23

OBJECT parameter description:

Parameter Name Type Required Description
success Function Yes the callback of successful interface call
fail Function No Callback function for interface call failure
complete Function No The callback function for the end of the interface call (it will be executed when the call succeeds or fails)

# success 返回参数说明

Parameter classification Parameter Description App platform value range Web platform value range MiniApp platform value range Remarks Minimum version requirements of the uni framework
device deviceId The device id. Generated and stored by the uni-app framework, clearing Storage will cause changes
deviceType The device type. Such as phone, pad, pc, unknow see phone, pad, pc, unknow phone, pad, pc uni-app 3.4.10+
deviceBrand Device brand. Such as: apple, huawei Not supported uni-app 3.4.10+
deviceModel Device model Some devices cannot be obtained uni-app 3.4.10+
deviceOrientation Device orientation vertical portrait, horizontal landscape vertical portrait, horizontal landscape vertical portrait, horizontal landscape. Only supported by WeChat and Baidu MiniApp uni-app 3.4.13+
devicePixelRatio 设备像素比 uni-app 3.4.13+
os osName 系统名称 ios、android ios、android、windows、macos、linux、harmonyos ios、android、windows、macos uni-app 3.4.10+
osVersion 操作系统版本。如 ios 版本,android 版本 uni-app 3.4.10+
osLanguage Operating system languageSee details Consistent with the browser language Not supported uni-app 3.4.10+
osTheme OS theme light, dark. The iOS platform can only get the theme of the system when the theme of the application is set to follow the system Not supported Not supported uni-app 3.4.10+
osAndroidAPILevel Android system API library version. For details, refer to Android Official Documentation Only supported by Android Not supported Not supported uni-app 3.4.10+
rom romName rom name The value cannot be obtained for some Android models, see details. iOS not supported not supported not supported uni-app 3.4.13+
romVersion rom version The value cannot be obtained for some Android models, see details. iOS not supported not supported not supported uni-app 3.4.13+
browser browserName Browser name or App webview name chrome (android), wkwebview (ios), x5webview (app packaging x5 engine) chrome, edge, safari, firefox not supported uni-app 3.4.10 +
browserVersion Browser version, webview version Not supported uni-app 3.4.10+
host hostName The integrated host name of the MiniApp host or uniMPSDK, such as: WeChat, `MiniApp Only supported by UniMPSDK Not supported See details value uni-app 3.4.10+
hostVersion Host version. Such as: WeChat version number Only supported by UniMPSDK Not supported MiniApp host version uni-app 3.4.10+
hostLanguage 宿主语言 仅 UniMPSDK 支持 不支持 小程序宿主语言 uni-app 3.4.10+
hostTheme 宿主主题 lightdark。仅 UniMPSDK 支持 lightdark lightdark。前提是微信小程序全局配置"darkmode":true时才能获取 uni-app 3.4.10+
hostFontSizeSetting 用户字体大小设置。以“我-设置-通用-字体大小”中的设置为准,单位:px 不支持 不支持 微信小程序、支付宝小程序、百度小程序、QQ小程序、抖音小程序(2.53.0+) uni-app 3.4.13+
hostPackageName MiniApp host package name Only supported by UniMPSDK Not supported Not supported uni-app 3.4.10+
hostSDKVersion uni MiniApp SDK version, MiniApp client base library version only supported by UniMPSDK not supported uni-app 3.4.13+
uni-app framework uniPlatform The running platform of uni-app is the same as the conditional compilation platform. See details app web or h5 various MiniApp, such as mp-weixin uni-app 3.4.10+
uniCompileVersion uni 编译器版本号。详见 3.4.103.2.9 3.4.103.2.9 3.4.103.2.9 uni-app 3.4.10+
uniCompilerVersion uni 编译器版本号。详见 3.4.103.2.9 3.4.103.2.9 3.4.103.2.9 uni-app +
uniRuntimeVersion uni runtime version. See 3.4.10, 3.2.9, etc. 3.4.10, 3.2.9, etc. 3.4.10, 3.2.9, etc. uni -app 3.4.10+
app appId manifest 中应用appid,即DCloud appid。 uni-app 3.4.10+
appName manifest 中应用名称 抖音小程序字段冲突,抖音小程序原字段与hostName一致 uni-app 3.4.10+
appVersion manifest 中应用版本名称。(标准基座模式下获取到的是基座的应用版本名称) uni-app 3.4.10+
appVersionCode manifest 中应用版本号。(标准基座模式下获取到的是基座的应用版本号) uni-app 3.4.10+
appWgtVersion Version name of the application resource (wgt). uni-app 3.4.15+
appLanguage Language set by the application en, zh-Hans, zh-Hant, fr, es en, zh-Hans, zh-Hant, fr, es en, zh-Hans, zh-Hant, fr, es uni-app 3.4.13+
Others ua userAgent ID Not Supported uni-app 3.4.10+
screenWidth screen width
screenHeight screen height
windowWidth Available window width
windowHeight Available window height
windowTop The top position of the available window
windowBottom 可使用窗口的底部位置
statusBarHeight 手机状态栏的高度
safeArea 在竖屏正方向下的安全区域。由于此属性理解和使用比较困难,更推荐使用 safeAreaInsets 属性。详见 微信、百度(开发者工具暂不支持,真机有效)、抖音、飞书、支付宝(iOS真机)、快手、QQ小程序、华为快应用
safeAreaInsets 在竖屏正方向下的安全区域插入位置。与小程序定义的 safeArea 用途相同,但是规范参考 iOS 平台的 safeAreaInsets 更利于理解和使用。详见 微信、百度(开发者工具暂不支持,真机有效)、抖音、飞书、支付宝小程序(iOS真机)、华为快应用 uni-app 2.5.3+

# 某些小程序特殊的返回参数

Parameter Description Platform Difference Description
benchmarkLevel Device performance level. Values: -2 or 0 (the device cannot run mini games), -1 (the performance is unknown), >=1 (the device performance value, the higher the value, the better the device performance, currently the highest is less than 50) WeChat MiniApp Android Version, QQ MiniApp Android Version
batteryLevel Remaining battery percentage (only valid for iOS) WeChat MiniApp
currentBattery Current battery percentage Alipay MiniApp
navigationBarHeight The height of the navigation bar Baidu MiniApp
titleBarHeight 标题栏高度 支付宝小程序
albumAuthorized 允许微信使用相册的开关(仅 iOS 有效) 微信小程序、小红书小程序
cameraAuthorized 允许微信使用摄像头的开关 微信小程序、小红书小程序
locationAuthorized 允许微信使用定位的开关 微信小程序、小红书小程序
microphoneAuthorized 允许微信使用麦克风的开关 微信小程序、小红书小程序
notificationAuthorized 允许微信通知的开关 微信小程序、小红书小程序
notificationAlertAuthorized 允许微信通知带有提醒的开关(仅 iOS 有效) 微信小程序
notificationBadgeAuthorized 允许微信通知带有标记的开关(仅 iOS 有效) 微信小程序、小红书小程序
notificationSoundAuthorized 允许微信通知带有声音的开关(仅 iOS 有效) 微信小程序、小红书小程序
bluetoothEnabled 蓝牙的系统开关 微信小程序、鸿蒙元服务、小红书小程序
locationEnabled 地理位置的系统开关 微信小程序、鸿蒙元服务、小红书小程序
wifiEnabled Wi-Fi 的系统开关 微信小程序、鸿蒙元服务、小红书小程序
cacheLocation Last cached location information Baidu MiniApp(minimum base library version 3.40.4 for Android; minimum supported version 3.70.2 for iOS)
storage 设备磁盘容量 支付宝小程序
OSApiVersion 系统 Api 版本 鸿蒙元服务

# 不推荐使用的返回参数,仅为向下兼容保留

Parameter Description Platform Difference Description
pixelRatio 设备像素比
brand 设备品牌。uni-app 3.4.10+ 后该字段为全小写,可能要做兼容处理 App、微信小程序、百度小程序、抖音小程序、飞书小程序、QQ小程序、小红书小程序
model Device model All platforms are supported. Specific models cannot be obtained for some devices on the web
system OS name and version, such as Android 10
language language set by the application
version Engine version number Web does not support
platform 客户端平台,值域为:iosandroidmac(3.1.10+)windows(3.1.10+)linux(3.1.10+)
host 宿主平台 百度小程序、小红书小程序
SDKVersion Client basic library version Alipay MiniApp and Web do not support
swanNativeVersion host platform version number Baidu MiniApp
app Currently running client Alipay MiniApp
AppPlatform App平台 QQ小程序
fontSizeSetting 用户字体大小设置。以“我-设置-通用-字体大小”中的设置为准,单位:px 微信小程序、支付宝小程序、百度小程序、QQ小程序、抖音小程序(2.53.0+)、小红书小程序(Android)

# uniPlatform 返回值说明

value valid condition
app App
web Web
mp-weixin WeChat MiniApp
mp-alipay Alipay MiniApp
mp-baidu 百度小程序
mp-toutiao 抖音小程序
mp-lark Feishu MiniApp
mp-qq QQ MiniApp
mp-kuaishou Kuaishou MiniApp
mp-jd JD MiniApp
mp-360 360小程序
mp-harmony 鸿蒙元服务
quickapp-webview QuickApp general (including Alliance, Huawei)
quickapp-webview-union QuickApp Union
quickapp-webview-huawei QuickApp Huawei

uniCompileVersion compiler version and uniRuntimeVersion runtime version, under normal circumstances should be the same value, that is, the version of uni-app.

If you use the uni-app that comes with HBuilder to develop, this value is equivalent to the version of HBuilder; if you use the separate uni-app cli to develop, it is equivalent to the cli version.

But on the App platform, the values of uniCompileVersion and uniRuntimeVersion will be different in some cases:

  • App cloud packaging chooses a packager version that does not match. For example, the HBuilder version is old and there is no corresponding packager in the cloud. At this time, uniCompileVersion will be smaller than uniRuntimeVersion after packaging.
  • The app is packaged offline, using a mismatched offline SDK
  • App wgt upgrade, that is, the app installed on the mobile phone is the old version uniRuntimeVersion, the new version of wgt uses a different version of HBuilder or uni-app cli version, and implements the application resource upgrade

# romName 返回值说明

value interpretation
MIUI Xiaomi
EMUI 华为
HarmonyOS 华为鸿蒙
ColorOS oppo
Funtouch OS vivo
FLymeOS Meizu
SmartisanOS Hammer

注意:

  • 不同rom的版本号规则不同,比如MIUI版本号是V130,而HarmonyOS的版本号是2.0.0
  • Harmony OS Next目前没有返回romName,此属性对应鸿蒙 deviceInfo 的 distributionOSName,目前Harmony OS Next deviceInfo 的 distributionOSName 属性为空字符串。

# hostName 返回值说明

value interpretation
WeChat WeChat
wxwork WeChat Enterprise Edition
Baidu host platform enumeration value list Baidu
alipay Alipay
amap Gold
DINGTALK DingTalk
UC UC Browser
QUARK Quark Browser
AK Ali Health
YK 优酷
qq QQ
KUAISHOU 快手
HarmonyOS 鸿蒙

# safeArea 返回值说明

Parameter Type Description
left Number Abscissa of the upper left corner of the safe area
right Number Abscissa of the lower right corner of the safe area
top Number The ordinate of the upper left corner of the safe area
bottom Number The vertical coordinate of the lower right corner of the safe area
width Number The width of the safe area, in logical pixels
height Number The height of the safe area, in logical pixels

Structure of safeAreaInsets

Parameter Type Description
left Number Insert position on the left side of the safe area
right Number Insert position on the right side of the safe area
top Number Insert position at the top of the safe area
bottom Number Insert position at the bottom of the safe area

# language 返回值说明

The international specification of language is BCP47 specification, which is divided into three sections, main language-secondary language-region. For example zh-Hans-CN means Chinese-Simplified-Mainland China

But except for the main language, the latter two can be omitted. On different platforms, their omission rules are also different.

  • app-ios, not omitted, returns zh-Hans-CN
  • app-android, web, WeChat MiniApp, omit sub-language, return zh-CN
  • The uni-app framework and multilingual applications, as well as the Alipay MiniApp, use zh-Hans to represent Simplified Chinese

Therefore, after obtaining the language, strings cannot be compared directly, and segments need to be compared. There is also a library on npm dedicated to comparing BCP47 language specification.

# deviceId 返回值说明

Web, MiniApp, and iOS are all platforms that strictly protect user privacy, and it is difficult to obtain effective unique device tags on these platforms.

Android has also improved user privacy protection. On very old mobile phones, you can obtain unlimited imei. On second-old mobile phones, when obtaining private information such as imei, you need to pop up a box to ask the user to authorize. New Android phones (Android10 and above) have been completely unable to obtain imei.

Therefore, most of the marking devices can only be marked by storing a random number locally.

deviceId, on the app-android platform, will use imei and mac according to the priority (only if the user has authorized, if it is found that authorization or unauthorized, skip this step), if not obtained, it will be randomly generated logo. Other platforms use randomly generated logos directly.

When using random numbers stored locally, the deviceId will become invalid in the following situations:

  • Uninstall apps
  • Reset App data on Android
  • The browser clears the cache or turns on the privacy mode,

For scenarios that require ad tracking under the app, idfa can be used on iOS, and [OAID](http://www. html5plus.org/doc/zh_cn/device.html#plus.device.getOAID)

# deviceModel 返回值说明

The uni-app 3.5.1+ version standardizes the return value of deviceModel. For example, the return value of iPhone11ProMax in the new version is iPhone 11 Pro Max. Each device model [reference specification](https://www.theiphonewiki.com/ wiki/Models) corresponding to the value of Generation

Note: Unknown will be displayed for a while after the new model is launched, and the official will adapt it as soon as possible.

# 其他注意

  • deviceType

    • app-ios 只支持 phonepad
    • app-android 支持 phonepadtvcarwatchvrapplianceundefinedunknown,关于各个类型的更详细解释参考Android官方文档
    • 其中,app-android 平台下 pad 类型的判断,在国产pad等非google官方设备上并不一定准确。如果有需要开发者可自行根据型号或屏幕大小判断。uni-app框架源码中判断pad的java代码如下,供参考:
    public static boolean isTablet(Context context) {
    	return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
    }
    
    • app-harmony 支持 phonepadtvwatchpcunknowncarvrundefined
  • osTheme: app-ios Only when the application theme is set to follow the system can the theme of the system be obtained. MiniApp have similar restrictions.

  • Screen height = native NavigationBar height (including status bar height) + usable window height + native TabBar height

  • windowHeight does not contain the height of NavigationBar and TabBar

  • On the Web side, windowTop is equal to the height of NavigationBar, and windowBottom is equal to the height of TabBar

  • On the App side, windowTop is equal to the height of the NavigationBar in the transparent state, and windowBottom is equal to the height of the TabBar in the transparent state

  • Highly relevant information should be obtained in onReady. Too early to get it.

Links to the documentation of this API in other MiniApp:

# 示例

Call code example

uni.getSystemInfo({
	success: function (res) {
		console.log(res.appName)
	}
});

The return value of getSystemInfo on different platforms (the table is long, you can drag the horizontal scroll bar after zooming the page)

Those marked with - are undefined, other values are the same as the listed items

Field Name App-Android App-iOS h5 Android uniMPsdk iOS uniMPsdk mp-weixin mp-alipay mp-baidu mp-toutiao
appId __UNI__8BB4001 __UNI__8BB4001 __UNI__8BB4001 __UNI__8BB4001 __UNI__8BB4001 __UNI__8BB4001 __UNI__8BB4001 __UNI__8BB4001 __UNI__8BB4001
appName test test test test test test test test test
appVersion 1.0.0 1.0.0 1.0.0 1.0.0 1.0.0 1.0.0 1.0.0 1.0.0 1.0.0
appVersionCode 100 100 100 100 100 100 100 100 100
appLanguage zh-Hans zh-Hans zh-Hans zh-Hans zh-Hans zh-Hans zh-Hans zh-Hans zh-Hans
browserName chrome wkwebview safari chrome wkwebview - - - -
browserVersion 96.0.4664.104 13.4.13 13.0.3 88.0.4324.93 15.4 - - - -
deviceId d3db0944da20f333 F791564F-853B-47B6-8CB8-27FF59315059 16518284854447835016 c7eafa7ed8774c0d F791564F-853B-47B6-8CB8-27FF59315059 1652178285720384773 16536215804846585135 1653359639811213582 16538995501084056633
deviceBrand xiaomi apple - huawei apple iphone iphone iphone apple
deviceModel Mi10Pro iPhone13ProMax iPhone MXW-AN00 iPhoneSimulator iPhone6/7/8Plus iPhone14,3 iPhone6/7/8 iPhone6
deviceType phone phone phone phone phone phone phone phone phone
deviceOrientation portrait portrait portrait portrait portrait portrait - portrait -
devicePixelRatio 2.5687501430511475 3 2 3 3 3 3 2 2
hostVersion - - 13.0.3 1.0 1.0.0 8.0.5 10.2.23 2.45.0 6.6.3
hostLanguage - - zh-CN zh-CN zh-Hans-CN zh-CN zh-CN zh-CN
hostTheme - - - light light - - - -
hostPackageName - - - com.example.mplauncherv3 io.dcloud.hellounimp - - - -
hostSDKVersion - - - 3.4.13 3.4.13 2.24.2 2.7.6 3.450.16 2.49.0
osName android ios ios android ios ios ios ios ios
osVersion 12 15.5 13.2.3 10 15.4 10.0.1 15.5 15.5 10.0.1
osLanguage zh-CN zh-Hans-CN - zh-CN zh-Hans-CN - - - -
osTheme light light - light light - - - -
osAndroidAPILevel 31 - - 29 - - - - - -
romName MIUI - - HarmonyOS - - - - -
romVersion V130 - - 2.0.0 - - - - -
uniPlatform app app web app app mp-weixin mp-alipay mp-baidu mp-toutiao
uniCompileVersion 3.4.13 3.4.13 3.4.13 3.4.13 3.4.13 3.4.13 3.4.13 3.4.13 3.4.13
uniRuntimeVersion 3.4.13 3.4.13 3.4.13 3.4.13 3.4.13 3.4.13 3.4.13 3.4.13 3.4.13

# uni.getSystemInfoSync()

A synchronous interface for obtaining system information. The call parameters and return value are the same as above getSystemInfo.

The content of device information is numerous and complex. Developers are welcome to test more environmental devices and edit this document to contribute.