window.plugins undefined in cordova-2.0.0 [closed]

2019-04-20 05:09发布

I'm trying to use the BarcodeScanner plugin for Cordova in a BlackBerry device without luck. The sample code makes use of this structure:

window.plugins.BarcodeScanner...

but window.plugins is undefined.

I tried with a fresh new application and window.plugins continues to be undefined (I mean, the sample application without any addition).

Did the api have changed and the documentation is outdated or there's something I'm missing?

Thanks!

4条回答
家丑人穷心不美
2楼-- · 2019-04-20 05:19

Finally, I used cordova 1.9.0, as plugins are not up-to-date yet.

Thanks to everyone!

查看更多
Anthone
3楼-- · 2019-04-20 05:25

Cordova 2.0 has removed the "addPlugin" method used by the BarcodeScanner plugin. So a quick fix would be to remove (or comment out) the "addConstructor" function used to add the plugin, and replace it with an explicit attachment to the window object:

//cordova.addConstructor(function() {
//    cordova.addPlugin('barcodeScanner', new BarcodeScanner());
//});

window.barcodeScanner = new BarcodeScanner();

Then, since "window.plugins" isn't used, you will also need to change the code that calls the "scan" method, so replace

window.plugins.barcodeScanner.scan(...

with

window.barcodeScanner.scan(...

I have tested this with Cordova 2.0 and it works.

查看更多
看我几分像从前
4楼-- · 2019-04-20 05:28

All, I pushed a new BarcodeScanner this morning that works with 2.0.0.

https://github.com/phonegap/phonegap-plugins/tree/master/Android/BarcodeScanner/2.0.0

查看更多
小情绪 Triste *
5楼-- · 2019-04-20 05:42

Just ran into the same problem. After looking into the window-object I found the BarcodeScanner being right there. Sowindow.BarcodeScanner.prototype.scan(result, error) did the trick. Make sure you wait for cordova to be fully initialized, otherwise you may get sth like has no method exec()

查看更多
登录 后发表回答