vue.js 从电容器配置文件中获取appId

pcww981p  于 2023-03-13  发布在  Vue.js
关注(0)|答案(1)|浏览(85)

有没有办法从capacitor.config.json文件中全局检索appId?在我的Quasar应用程序中,我使用这个来链接回应用程序。所以当我将它从应用程序的“dev "版本更改为”prod“版本时,我需要在我的Vue组件文件中更改它,info.plist适用于ios,strings.xml适用于android。
UPD:从这个线程中,我知道it's not possible只能通过capacitor.config.json来处理。但是有什么解决办法呢?

aemubtdh

aemubtdh1#

从电容器3开始,应用程序信息从设备插件移动到应用程序插件。
首先安装插件

npm install @capacitor/app
npx cap sync

现在,您可以在应用程序中使用它

import { App } from '@capacitor/app';

const info = await App.getInfo();
console.log(info);

https://capacitorjs.com/docs/apis/app#appinfo
对于电容器2和更早版本,您可以使用设备插件,getInfo函数包含appId

import { Plugins } from '@capacitor/core';

const { Device } = Plugins;

const info = await Device.getInfo();
console.log(info);

// Example output:
{
  "diskFree": 12228108288,
  "appVersion": "1.0.2",
  "appBuild": "123",
  "appId": "com.capacitorjs.myapp",
  "appName": "MyApp",
  "operatingSystem": "ios",
  "osVersion": "11.2",
  "platform": "ios",
  "memUsed": 93851648,
  "diskTotal": 499054952448,
  "model": "iPhone",
  "manufacturer": "Apple",
  "uuid": "84AE7AA1-7000-4696-8A74-4FD588A4A5C7",
  "isVirtual":true
}

https://capacitorjs.com/docs/apis/device#getinfo

相关问题