# uni.getSystemInfo(options)

异步获取系统信息

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:开发者的应用相关的信息,如应用名称、版本

详见

# # Parameters

name type required default description
options GetSystemInfoOptions YES - -

# # GetSystemInfoOptions Values

name type optinal default description
success (result: GetSystemInfoResult) => void NO null 接口调用成功的回调函数
fail (result: UniError) => void NO null 接口调用失败的回调函数
complete (result: any) => void NO null 接口调用结束的回调函数(调用成功、失败都会执行)
# # GetSystemInfoResult Values
name type optinal default description
SDKVersion string YES - 客户端基础库版本
appId string YES - manifest.json 中应用appid。
appLanguage string YES - 应用设置的语言。
appName string YES - manifest.json 中应用名称。
appVersion string YES - manifest.json 中应用版本名称。
appVersionCode string YES - manifest.json 中应用版本名号。
brand string YES - 手机品牌。
browserName string YES - 浏览器名称。App 端是系统 webview 的名字,比如 wkwebview、chrome。小程序端为空
browserVersion string YES - 浏览器版本、webview 版本。
deviceId string YES - 设备 ID
deviceBrand string YES - 设备品牌。如:applehuawei
deviceModel string YES - 设备型号
deviceType string YES - 设备类型。phonepadpc
devicePixelRatio number YES - 设备像素比
deviceOrientation string YES - 设备方向。如:竖屏 portrait横屏 landscape - portrait: 竖屏 - landscape: 横屏
language string YES - 程序设置的语言
osName string YES - ios、android、windows、mac、linux
osVersion string YES - 操作系统版本。如 ios 版本,andriod 版本
osLanguage string YES - 操作系统语言
pixelRatio number YES - 设备像素比
platform string YES - 客户端平台
screenWidth number YES - 屏幕宽度
screenHeight number YES - 屏幕高度
statusBarHeight number YES - 状态栏的高度
system string YES - 操作系统版本
safeArea SafeArea YES - 在竖屏正方向下的安全区域
safeAreaInsets SafeAreaInsets YES - 在竖屏正方向下的安全区域插入位置
ua string YES - 用户标识。小程序端为空
uniCompileVersion string YES - uni 编译器版本
uniPlatform string YES - uni-app 运行平台。如:appmp-weixinweb
uniRuntimeVersion string YES - uni 运行时版本
uniCompileVersionCode number YES - uni 编译器版本号
uniRuntimeVersionCode number YES - uni 运行时版本号
version string YES - 引擎版本号。已废弃,仅为了向下兼容保留
romName string YES - rom 名称。Android 部分机型获取不到值。iOS 恒为 ios
romVersion string YES - rom 版本号。Android 部分机型获取不到值。iOS 恒为 ios 版本号
windowWidth number YES - 可使用窗口宽度
windowHeight number YES - 可使用窗口高度
windowTop number YES - 可使用窗口的顶部位置
oaid string NO - oaid
osAndroidAPILevel number NO - Android 系统API库的版本。
# # SafeArea Values
name type optinal default description
left number YES - 安全区域左上角横坐标
right number YES - 安全区域右下角横坐标
top number YES - 安全区域左上角纵坐标
bottom number YES - 安全区域右下角纵坐标
width number YES - 安全区域的宽度,单位逻辑像素
height number YES - 安全区域的高度,单位逻辑像素
# # SafeAreaInsets Values
name type optinal default description
left number YES - 安全区域左侧插入位置
right number YES - 安全区域右侧插入位置
top number YES - 安全区顶部插入位置
bottom number YES - 安全区域底部插入位置
# # GetSystemInfoResult Compatibility
Android version Android uni-app Android uni-app-x iOS version iOS uni-app iOS uni-app-x
oaid 4.4 x x x
osAndroidAPILevel 4.4 x x x

# # getSystemInfo Compatibility

Android version Android uni-app Android uni-app-x iOS version iOS uni-app iOS uni-app-x
4.4 3.9+ 9.0 x

# # See also

getSystemInfo

Related Bug

# uni.getSystemInfoSync()

同步获取系统信息

# # Return value

Type
GetSystemInfoResult

# # GetSystemInfoResult Values

name type optinal default description
SDKVersion string YES - 客户端基础库版本
appId string YES - manifest.json 中应用appid。
appLanguage string YES - 应用设置的语言。
appName string YES - manifest.json 中应用名称。
appVersion string YES - manifest.json 中应用版本名称。
appVersionCode string YES - manifest.json 中应用版本名号。
brand string YES - 手机品牌。
browserName string YES - 浏览器名称。App 端是系统 webview 的名字,比如 wkwebview、chrome。小程序端为空
browserVersion string YES - 浏览器版本、webview 版本。
deviceId string YES - 设备 ID
deviceBrand string YES - 设备品牌。如:applehuawei
deviceModel string YES - 设备型号
deviceType string YES - 设备类型。phonepadpc
devicePixelRatio number YES - 设备像素比
deviceOrientation string YES - 设备方向。如:竖屏 portrait横屏 landscape - portrait: 竖屏 - landscape: 横屏
language string YES - 程序设置的语言
osName string YES - ios、android、windows、mac、linux
osVersion string YES - 操作系统版本。如 ios 版本,andriod 版本
osLanguage string YES - 操作系统语言
pixelRatio number YES - 设备像素比
platform string YES - 客户端平台
screenWidth number YES - 屏幕宽度
screenHeight number YES - 屏幕高度
statusBarHeight number YES - 状态栏的高度
system string YES - 操作系统版本
safeArea SafeArea YES - 在竖屏正方向下的安全区域
safeAreaInsets SafeAreaInsets YES - 在竖屏正方向下的安全区域插入位置
ua string YES - 用户标识。小程序端为空
uniCompileVersion string YES - uni 编译器版本
uniPlatform string YES - uni-app 运行平台。如:appmp-weixinweb
uniRuntimeVersion string YES - uni 运行时版本
uniCompileVersionCode number YES - uni 编译器版本号
uniRuntimeVersionCode number YES - uni 运行时版本号
version string YES - 引擎版本号。已废弃,仅为了向下兼容保留
romName string YES - rom 名称。Android 部分机型获取不到值。iOS 恒为 ios
romVersion string YES - rom 版本号。Android 部分机型获取不到值。iOS 恒为 ios 版本号
windowWidth number YES - 可使用窗口宽度
windowHeight number YES - 可使用窗口高度
windowTop number YES - 可使用窗口的顶部位置
oaid string NO - oaid
osAndroidAPILevel number NO - Android 系统API库的版本。
# # SafeArea Values
name type optinal default description
left number YES - 安全区域左上角横坐标
right number YES - 安全区域右下角横坐标
top number YES - 安全区域左上角纵坐标
bottom number YES - 安全区域右下角纵坐标
width number YES - 安全区域的宽度,单位逻辑像素
height number YES - 安全区域的高度,单位逻辑像素
# # SafeAreaInsets Values
name type optinal default description
left number YES - 安全区域左侧插入位置
right number YES - 安全区域右侧插入位置
top number YES - 安全区顶部插入位置
bottom number YES - 安全区域底部插入位置
# # GetSystemInfoResult Compatibility
Android version Android uni-app Android uni-app-x iOS version iOS uni-app iOS uni-app-x
oaid 4.4 x x x
osAndroidAPILevel 4.4 x x x

# # getSystemInfoSync Compatibility

Android version Android uni-app Android uni-app-x iOS version iOS uni-app iOS uni-app-x
4.4 3.9+ 9.0 x

# # See also

getSystemInfoSync

Related Bug

# # Example

hello uni-app x

<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">
             <textarea
               :auto-height="true"
               :disabled="true"
               placeholder="未获取"
               :value="item.value"
             />
           </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>
<script>
type Item = {
   label : string,
   value : string,
}
export default {
   data() {
   	return {
   		title: 'getSystemInfo',
   		items: [] as Item[],
   	}
   },
   onUnload: function () {
   },
   methods: {
   	getSystemInfo: function () {
   		uni.getSystemInfo({
   			success: (res) => {
         this.items = [] as Item[];
         for(const key in res){
           const value = res[key];
           if(value != null){
             const item = {
             	label: key,
             	value: "" + ((typeof value == "object")? JSON.stringify(value) : value)
             } as Item;
             this.items.push(item);
           }
         }
   			},
   		})
   	},
   getSystemInfoSync: function () {
     this.items = [] as Item[];
     const res = uni.getSystemInfoSync()
   	for(const key in res){
   	  const value = res[key];
   	  if(value != null){
   	    const item = {
   	    	label: key,
   	    	value: "" + ((typeof value == "object")? JSON.stringify(value) : value)
   	    } as Item;
   	    this.items.push(item);
   	  }
   	}
   },
   //自动化测试例专用
   jest_getSystemInfo():GetSystemInfoResult{
     return uni.getSystemInfoSync();
   },
   }
}
</script>

<style>
.uni-pd {
 padding-left: 30rpx;
}
</style>

# # General type

# # GeneralCallbackResult

name type optinal default description
errMsg string YES - 错误信息