Separate mobile and desktop code?

#1

I’m currently using Ionic 4 to make the mobile apps. with usages of cordova native plugins i know it won’t work with the desktop platform. should i continue to use ionic for desktop/browser and just add platform.is(‘cordova’) to not execute any cordova native plugins? or is there a better way to handle this? or i might need to write another angular project targeting browser?

#2

Hi @pefe,

Checking platform.is('cordova') to avoid calling native plugins on the browser is the way to go. My advice is to use the same project for all platforms, otherwise you won’t be benefiting from having a single codebase.

A little trick: since you also have to wait for platform.ready() before you use a plugin, this promise also returns cordova or dom, so you don’t have to use platform.is('cordova') later:

async myFunction() {
  const readySource = await this.platform.ready();

  if (readySource === 'cordova') {
    usePlugin();
  }
}

Best,
Rodrigo