window.plugins undefined in cordova-2.0.0 [closed]

空扰寡人 提交于 2019-12-05 02:17:46

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

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.

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()

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

Thanks to everyone!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!