Back to Uni App

Get App Base Info

docs/api/get-app-base-info.md

2.3.314.7 KB
Original Source
<!-- ## uni.getAppBaseInfo(options?) @getappbaseinfo -->

::: sourceCode

uni.getAppBaseInfo(options?) @getappbaseinfo

GitCode: https://gitcode.com/dcloud/uni-api/tree/alpha/uni_modules/uni-getAppBaseInfo

GitHub: https://github.com/dcloudio/uni-api/tree/alpha/uni_modules/uni-getAppBaseInfo

:::

获取app基本信息

getAppBaseInfo 兼容性

Web微信小程序AndroidiOSiOS uni-app x UTS 插件HarmonyOSHarmonyOS(Vapor)
4.04.413.914.114.114.615.0

参数

名称类型必填默认值兼容性描述
optionsGetAppBaseInfoOptions包含所有字段的过滤对象Web: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -[options=包含所有字段的过滤对象] 过滤的字段对象, 不传参数默认为获取全部字段。

options 的属性描述

名称类型必备默认值兼容性描述
filterArray<string>-Web: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: -过滤字段的字符串数组,假如要获取指定字段,传入此数组。

返回值

类型
GetAppBaseInfoResult

GetAppBaseInfoResult 的属性描述

名称类型必备默认值兼容性描述
appIdstring-Web: 4.0; 微信小程序: 4.41; Android: 3.91; iOS: 4.11; iOS uni-app x UTS 插件: 4.11; HarmonyOS: 4.61; HarmonyOS(Vapor): 5.0manifest.json 中应用appid,即DCloud appid。
appNamestring-Web: 4.0; 微信小程序: 4.41; Android: 3.91; iOS: 4.11; iOS uni-app x UTS 插件: 4.11; HarmonyOS: 4.61; HarmonyOS(Vapor): 5.0manifest.json 中应用名称。
appVersionstring-Web: 4.0; 微信小程序: 4.41; Android: 3.91; iOS: 4.11; iOS uni-app x UTS 插件: 4.11; HarmonyOS: 4.61; HarmonyOS(Vapor): 5.0manifest.json 中应用版本名称,如果离线打包注意修改修改index.kt中UniAppConfig类型中的版本名称文档
appVersionCodestring-Web: 4.0; 微信小程序: 4.41; Android: 3.91; iOS: 4.11; iOS uni-app x UTS 插件: 4.11; HarmonyOS: xmanifest.json 中应用版本号,如果离线打包注意修改修改index.kt中UniAppConfig类型中的版本号文档
appLanguagestring-Web: 4.0; 微信小程序: 4.41; Android: 3.91; iOS: 4.11; iOS uni-app x UTS 插件: 4.11; HarmonyOS: x应用设置的语言en、zh-Hans、zh-Hant、fr、es
languagestring-Web: 4.0; 微信小程序: 4.41; Android: 3.91; iOS: 4.11; iOS uni-app x UTS 插件: 4.11; HarmonyOS: x应用设置的语言
appWgtVersionstring-Web: x; 微信小程序: x; Android: x; iOS: x; iOS uni-app x UTS 插件: x; HarmonyOS: 4.61; HarmonyOS(Vapor): 5.0应用资源(wgt)的版本名称。
hostLanguagestring-Web: x; 微信小程序: 4.41; Android: x; iOS: x; iOS uni-app x UTS 插件: x; HarmonyOS: 4.61; HarmonyOS(Vapor): 5.0小程序宿主语言
hostVersionstring-Web: x; 微信小程序: 4.41; Android: x; iOS: x; iOS uni-app x UTS 插件: x; HarmonyOS: xApp、小程序宿主版本。
hostNamestring-Web: x; 微信小程序: 4.41; Android: x; iOS: x; iOS uni-app x UTS 插件: x; HarmonyOS: x小程序宿主名称
hostPackageNamestring-Web: x; 微信小程序: x; Android: x; iOS: x; iOS uni-app x UTS 插件: x; HarmonyOS: x小程序宿主包名
hostSDKVersionstring-Web: x; 微信小程序: 4.41; Android: x; iOS: x; iOS uni-app x UTS 插件: x; HarmonyOS: xuni小程序SDK版本、小程序客户端基础库版本
hostThemestring-Web: 4.0; 微信小程序: 4.41; Android: x; iOS: x; iOS uni-app x UTS 插件: x; HarmonyOS: x系统当前主题,取值为light或dark。微信小程序全局配置"darkmode":true时才能获取,否则为 null (不支持小游戏)
isUniAppXboolean-Web: 4.18; 微信小程序: 4.41; Android: 3.91; iOS: 4.11; iOS uni-app x UTS 插件: 4.11; HarmonyOS: x是否uni-app x
uniCompilerVersionstring-Web: 4.18; 微信小程序: 4.41; Android: 4.0; iOS: 4.11; iOS uni-app x UTS 插件: 4.11; HarmonyOS: 4.61; HarmonyOS(Vapor): 5.0uni 编译器版本
uniPlatformstring-Web: 4.0; 微信小程序: 4.41; Android: 3.91; iOS: 4.11; iOS uni-app x UTS 插件: 4.11; HarmonyOS: 4.61; HarmonyOS(Vapor): 5.0uni-app 运行平台。
uniRuntimeVersionstring-Web: 4.18; 微信小程序: 4.41; Android: 3.91; iOS: 4.11; iOS uni-app x UTS 插件: 4.11; HarmonyOS: xuni 运行时版本
uniCompilerVersionCodenumber-Web: 4.18; 微信小程序: 4.41; Android: 4.0; iOS: 4.11; iOS uni-app x UTS 插件: 4.11; HarmonyOS: 4.61; HarmonyOS(Vapor): 5.0uni 编译器版本号
uniRuntimeVersionCodenumber-Web: 4.0; 微信小程序: 4.41; Android: 3.91; iOS: 4.11; iOS uni-app x UTS 插件: 4.11; HarmonyOS: 4.61; HarmonyOS(Vapor): 5.0uni 运行时版本号
packageNamestring-Web: x; 微信小程序: x; Android: 3.97; iOS: x; iOS uni-app x UTS 插件: x; HarmonyOS: 4.61; HarmonyOS(Vapor): 5.0Android的包名
bundleNamestring-Web: x; 微信小程序: x; Android: x; iOS: x; iOS uni-app x UTS 插件: x; HarmonyOS: 4.61; HarmonyOS(Vapor): 5.0鸿蒙的包名
bundleIdstring-Web: x; 微信小程序: x; Android: x; iOS: 4.11; iOS uni-app x UTS 插件: 4.11; HarmonyOS: xiOS的bundleId
signaturestring-Web: x; 微信小程序: x; Android: 3.97; iOS: 4.11; iOS uni-app x UTS 插件: 4.11; HarmonyOS: xAndroid: 应用签名证书的SHA1值(全部为小写,中间不包含“:”)。
iOS: 应用签名证书中绑定的Bundle ID(AppleID)的md5值(全部为小写)。
appThemestring-Web: x; 微信小程序: x; Android: 4.18; iOS: 4.18; iOS uni-app x UTS 插件: 4.18; HarmonyOS: 4.61; HarmonyOS(Vapor): 5.0当前App的主题
channelstring-Web: x; 微信小程序: x; Android: 4.28; iOS: 4.31; iOS uni-app x UTS 插件: 4.31; HarmonyOS: x当前应用分发的渠道
SDKVersionstring-Web: -; 微信小程序: 4.41; Android: -; iOS: -; HarmonyOS: -客户端基础库版本
enableDebugboolean-Web: -; 微信小程序: 4.41; Android: -; iOS: -; HarmonyOS: -
fontSizeScaleFactornumber-Web: -; 微信小程序: 4.41; Android: -; iOS: -; HarmonyOS: -微信字体大小缩放比例
fontSizeSettingnumber-Web: -; 微信小程序: 4.41; Android: -; iOS: -; HarmonyOS: -需要基础库: 2.23.4

微信字体大小,单位px | | host | GetAppBaseInfoResultHost | 否 | - | Web: -; 微信小程序: 4.41; Android: -; iOS: -; HarmonyOS: - | 当前小程序运行的宿主环境 | | theme | string | 否 | - | Web: -; 微信小程序: 4.41; Android: -; iOS: -; HarmonyOS: - | 系统当前主题,取值为lightdark,全局配置"darkmode":true时才能获取,否则为 undefined (不支持小游戏)

可选值:

  • 'dark': 深色主题;
  • 'light': 浅色主题; | | version | string | 否 | - | Web: x; 微信小程序: 4.41; Android: 3.91; iOS: 4.11; iOS uni-app x UTS 插件: 4.11; HarmonyOS: 4.61; HarmonyOS(Vapor): 5.0 | 引擎版本号。已废弃,仅为了向下兼容保留 已废弃,仅为了向下兼容保留 | | uniCompileVersion | string | 否 | - | Web: x; 微信小程序: 4.41; Android: 3.91; iOS: 4.11; iOS uni-app x UTS 插件: 4.11; HarmonyOS: x | uni 编译器版本 已废弃,仅为了向下兼容保留 | | uniCompileVersionCode | number | 否 | - | Web: x; 微信小程序: 4.41; Android: 3.91; iOS: 4.11; iOS uni-app x UTS 插件: 4.11; HarmonyOS: 4.61; HarmonyOS(Vapor): 5.0 | uni 编译器版本号 已废弃,仅为了向下兼容保留 |
uniPlatform 的属性描述
合法值兼容性描述
appWeb: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: --
webWeb: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: --
mp-weixinWeb: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: --
mp-alipayWeb: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: --
mp-baiduWeb: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: --
mp-toutiaoWeb: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: --
mp-larkWeb: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: --
mp-qqWeb: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: --
mp-kuaishouWeb: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: --
mp-jdWeb: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: --
mp-360Web: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: --
quickapp-webviewWeb: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: --
quickapp-webview-unionWeb: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: --
quickapp-webview-huaweiWeb: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: --
appTheme 的属性描述
合法值兼容性描述
lightWeb: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: --
darkWeb: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: --
autoWeb: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: --
host 的属性描述
名称类型必备默认值兼容性描述
appIdstring-Web: -; 微信小程序: 4.41; Android: -; iOS: -; HarmonyOS: -宿主 app(第三方App) 对应的 appId (当小程序运行在第三方App环境时才返回)
theme 的属性描述
合法值兼容性描述
darkWeb: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: --
lightWeb: -; 微信小程序: -; Android: -; iOS: -; HarmonyOS: --

appTheme @apptheme

获取应用的主题配置信息,仅app平台支持。 appTheme返回值为auto,代表跟随系统。此时需通过getSystemInfogetDeviceInfo查询osTheme获取当前到底是light还是dark。

channel @channel

获取应用的渠道信息,仅app-android平台支持渠道包。

示例

示例为hello uni-app x alpha分支,与最新HBuilderX Alpha版同步。与最新正式版同步的master分支示例另见 ::: preview https://hellouniappx.dcloud.net.cn/web/#/pages/API/get-app-base-info/get-app-base-info

appRedirect https://hellouniappx.dcloud.net.cn/appredirect.html?path=pages/API/get-app-base-info/get-app-base-info

示例

vue
<template>
  <page-head :title="title"></page-head>
  <view class="uni-common-mt">
    <view class="uni-list">
      <view class="uni-list-cell" v-for="(item, index) in data.items" :key="index" 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 class="uni-list-cell-db-text">{{ item.value == '' ? '未获取' : item.value }}</text>
        </view>
      </view>
    </view>
    <view class="uni-padding-wrap">
      <view class="uni-btn-v">
        <button type="primary" @tap="getAppBaseInfo">获取App基础信息</button>
      </view>
    </view>
  </view>
</template>
<script setup lang="uts">
  type Item = {
    label : string,
    value : string,
  }

  type DataType = {
    items: Item[];
  }

  const title = ref('getAppBaseInfo')
  const data = reactive({
    items: [] as Item[],
  } as DataType)

  const getAppBaseInfo = () => {
    const res = uni.getAppBaseInfo();
    const res_str = JSON.stringify(res);
    const res_obj = JSON.parseObject(res_str);
    const res_map = res_obj!.toMap();
    let keys = [] as string[]
    res_map.forEach((_, key) => {
      keys.push(key);
    });

    data.items = [] as Item[];
    keys.sort().forEach(key => {
      const value = res[key];
      if (value != null) {
        const item = {
          label: key,
          value: "" + ((typeof value == "object") ? JSON.stringify(value) : value)
        } as Item;
        data.items.push(item);
      }
    });
  }

</script>

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

:::

参见

通用类型

GeneralCallbackResult

名称类型必备默认值兼容性描述
errMsgstring-Web: -; 微信小程序: 4.41; Android: -; iOS: -; HarmonyOS: -错误信息