0

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Did you manage to solve this? Same problem here with 'cordova/exec` not being found within a plugin – alanionita Jul 20 '21 at 14:02
  • @alanionita My "solution' was to starting using Ionic :) –  Jul 25 '21 at 00:10
  • @e-maggini did you find Ionic to be more stable over the Meteor+Cordova? Having a few issues atm with integrating gradle dependencies into a Cordova plugin. – alanionita Jul 26 '21 at 08:51
  • @alanionita Generally speaking I would say Ionic is the "go to" these days for hybrid application development. I've been working on an enterprise financial app for 1.5 years and have had good experience integrating existing cordova plugins as well as writing my own. I must admit I don't love the direction Ionic is going with Capacitor but as long as Cordova remains a viable options I will remain with Ionic. –  Jul 26 '21 at 12:23

2 Answers2

1

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)

}

alanionita
  • 1,272
  • 1
  • 16
  • 34
0

var exec = require('cordova/exec');