meteor / meteor

Meteor, the JavaScript App Platform
https://meteor.com
Other
44.28k stars 5.17k forks source link

Could more specific example given to use Cordova plugin directly? #3192

Closed johnsonqu closed 9 years ago

johnsonqu commented 9 years ago

Even we already had one guidance on integration with Cordova and listed how to add Cordova plugin directly. But it's still not clear how to ensure the plugin could be called successfully.

I'm using Meteor, Angular and Cordova plugin together and would like to build one page for barcode scan.

Pls check below code to call Cordova plugin. It seems that 'cordova' couldn't be found. angular.module("qrcode").controller("ScanInCtrl", ['$scope', '$collection', function($scope, $collection){ $scope.barcode = ''; $scope.scan = function(){ cordova.plugins.barcodeScanner.scan( function (result) { $scope.barcode = "Result: " + result.text + "\n" + "Format: " + result.format + "\n" + "Cancelled: " + result.cancelled; }, function (error) { alert("Scanning failed: " + error); } );

    };
  }
]);
roryqueue commented 9 years ago

John, did you figure this out? Is there a more robust example out there? I'm also having a problem accessing plugins via cordova.plugins.XXXX. I have a feeling I'm doing something dumb but I'd appreciate any insight.

johnsonqu commented 9 years ago

I finally installed the plugin since it is registered already. Then I 'meteor run iOS', it would download the plugin and build it for iOS. If you run it in web browser, it won't work.

roryqueue commented 9 years ago

Thanks Johnson. just in case anyone runs into a similar problem, here is what I was doing wrong --

I was porting a cordova project to meteor, and in the original repo I was calling the AppPlant's emailComposer plugin via cordova.plugins.email. I needed to call it via window.plugin.email in Meteor (which is the way it is demonstrated at plugins.cordova.io) in order to access it.