ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web ⚡️
https://capacitorjs.com
MIT License
12.16k stars 1.01k forks source link

Method for checking plugin availability #722

Closed ArmorDarks closed 6 years ago

ArmorDarks commented 6 years ago

Current behavior

There is no way to check whether certain plugin method is available on a current platform.

The only workaround is to invoke the method and to catch its error. In some cases that can be troublesome, because it might invoke undesired side effects. Add on top issues with types like #720 which makes it really hard.

Expected behavior

Should be a method like Plugins.App.openUrl.isAvailable() for each plugin which will check whether the method has an implementation fur current platform.

jcesarmobile commented 6 years ago

Issues tagged with feature request are closed but tracked for reactions to gauge interest.

My personal opinion is that this should not be needed and will create very complex code if for every call you have to check if it's available first. But we should probably improve the docs about which methods are supported in each platforms.

ArmorDarks commented 6 years ago

My personal opinion is that this should not be needed and will create very complex code if for every call you have to check if it's available first.

It already does create very complex code, because not always you want to check current platform to do something.

For instance, to use Plugins.App.canOpenUrl you need to ensure that you're on the iOS or Android platform at first place, though often you don't want to be dependant on the platform checks at all and just to know is it method available or no.

jcesarmobile commented 3 years ago

on Capacitor 3 the plugins can throw unimplemented error that can be catch from javascript like this

try {
    Capacitor.Plugins.MyPlugin.unimplementedMethodOnAndroid();
} catch (e) {
      if (e.code === 'UNIMPLEMENTED') {
          // Do something different on android
      }
}

and all our plugins all the methods should be defined, but will throw this error if not implemented, other plugins should do the same

ionitron-bot[bot] commented 1 year ago

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.