Closed ArmorDarks closed 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.
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.
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
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.
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.