Is there a way to tell if a specific Cordova plugin is available to be called in Cordova 2.5.0? Cordova.exec
takes in a successFunction
and a failFunction
but the failFunction
is only called if the native code executes. Is there a way to receive an error or callback if the receiving function doesn't exist? I'm looking for a solution that works with a remove URL loaded into WebView
http://docs.phonegap.com/en/2.5.0/guide_plugin-development_ios_index.md.html
Add an event listener (load) for the cordova script that creates a boolean variable in the window ( usingCordova ) initially set to false and then once the cordova script loads, it will be set to true. Then you can use a simple if statement verifying wheter cordova was loaded or not.
To find the locally installed version of Cordova CLI run cordova -v (If you are using Ionic, this version is also included in the ionic info output). Then compare the returned version number to the output of npm info cordova version (You can also check manually for the newest available version on npm or GitHub).
For a quite simpler (and cleaner) solution, you can also use this method :
var plugins = cordova.require("cordova/plugin_list").metadata;
You'll get an object looking like that :
{
'cordova-plugin-network-information': "1.0.0",
'cordova-plugin-whitelist': "1.0.0"
}
As any normal variable, you can then check if it's defined :
if (typeof plugins['cordova-plugin-whitelist'] === "undefined")
{
// This plugin is missing
}
you can do a setTimeout for 100 ms before trying to access the plugin, and on success/failure of the plugin cancel the timeout. if the timeout triggers - the plugin is not installed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With