Get appId form Capacitor config file

Viewed 691

Is there a way to retrieve appId globally from capacitor.config.json file? In my Quasar app I use this for linking back to the app. So when I change it from 'dev' to 'prod' version of the app I need to change it in my Vue component file, info.plist for ios and strings.xml for android.

UPD: From this thread I've known that it's not possible to handle just via capacitor.config.json. But what could be a workaround?

1 Answers

You can use Device plugin, the getInfo function contains the 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

Related