Search code examples
cordovameteor

Is there a Meteor equivalent to cordova.exec?


I am looking at this Stack Overflow question

I am working on a project using Meteor. It also uses the Canvas2ImagePlugin which is a Cordova plugin.

I have successfully added it to the project using meteor add cordova:https://github.com/devgeeks/Canvas2ImagePlugin.git@0.6.0

However, the code snippet

           cordova.exec(
            success,
            error,
            'Canvas2ImagePlugin',
            'saveImageDataToLibrary',
            [imageData]
        );

fails in Meteor since Cordova doesn't exist.

How to make this call in a Meteor way or otherwise expose Cordova to Meteor project?


Solution

  • Within Meteor you'll need to use cordova from the global object since Meteor will inject the cordova object.

    // First lets check that we are running withing Cordova
    if (Meteor.isCordova) {
    
        // define your success and fail functions here
        function success() {
           // Do something
           console.log('Success')
        }
    
        function fail() {
           // Do something
           console.log('fail')
        }
    
        // Execute the cordova plugin method
        cordova.exec(success, fail, 'PluginName', 'pluginMethod', pluginMethodArguments)
    
    }