Search code examples
vue.jscapacitorquasar-frameworkquasar

Get appId form Capacitor config file


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?


Solution

  • Since capacitor 3, the app info was moved from device plugin to app plugin.

    First install the plugin

    npm install @capacitor/app
    npx cap sync
    

    Now you can use it in your app

    import { App } from '@capacitor/app';
    
    const info = await App.getInfo();
    console.log(info);
    

    https://capacitorjs.com/docs/apis/app#appinfo

    For Capacitor 2 and older 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