有谁能让BarcodeScanning插件PhoneGap在PhoneGap 1.7.0上工作吗?
条形码扫描插件:https://github.com/phonegap/phonegap-plugins/tree/master/iOS/BarcodeScanner
问题是插件添加时没有设置..。
当我调用“警报(window.plugins.barcodeScanner)”时,会得到以下信息:
“未定义”
我试图隔离插件没有被添加的地方,一旦我知道更多的话,我会更新这个问题。
谢谢你能帮上忙.
最新答复如下:
发布于 2012-06-03 11:15:05
好的,经过一番探索,并以twitter PhoneGap插件为例,我设法让它工作了!!
我用它作为我的方法的基础,因为推特上可爱的人更新了他们的插件,使用PhoneGap 1.7.0,谢天谢地!
Twitter PhoneGap插件: https://github.com/phonegap/phonegap-plugins/blob/master/iOS/Twitter/js/TwitterPlugin.js
这里是更新的barcodescanner.js代码:
var BarcodeScanner = function(){};
BarcodeScanner.prototype.isBarcodeScannerAvailable = function(response){
cordova.exec(response, null, "BarcodeScannerPlugin", "isBarcodeScannerAvailable", []);
};
BarcodeScanner.prototype.isBarcodeScannerSetup = function(response){
cordova.exec(response, null, "BarcodeScannerPlugin", "isBarcodeScannerSetup", []);
};
//-------------------------------------------------------------------
BarcodeScanner.Encode = {
TEXT_TYPE: "TEXT_TYPE",
EMAIL_TYPE: "EMAIL_TYPE",
PHONE_TYPE: "PHONE_TYPE",
SMS_TYPE: "SMS_TYPE",
CONTACT_TYPE: "CONTACT_TYPE",
LOCATION_TYPE: "LOCATION_TYPE"
}
//-------------------------------------------------------------------
BarcodeScanner.prototype.scan = function(success, fail, options) {
function successWrapper(result) {
result.cancelled = (result.cancelled == 1)
success.call(null, result)
}
if (!fail) { fail = function() {}}
if (typeof fail != "function") {
console.log("BarcodeScanner.scan failure: failure parameter not a function")
return
}
if (typeof success != "function") {
fail("success callback parameter must be a function")
return
}
if ( null == options )
options = []
return PhoneGap.exec(successWrapper, fail, "com.cordova.barcodeScanner", "scan", options)
}
//-------------------------------------------------------------------
BarcodeScanner.prototype.encode = function(type, data, success, fail, options) {
if (!fail) { fail = function() {}}
if (typeof fail != "function") {
console.log("BarcodeScanner.scan failure: failure parameter not a function")
return
}
if (typeof success != "function") {
fail("success callback parameter must be a function")
return
}
return PhoneGap.exec(success, fail, "com.cordova.barcodeScanner", "encode", [{type: type, data: data, options: options}])
}
cordova.addConstructor(function() {
/* shim to work in 1.5 and 1.6 */
if (!window.Cordova) {
window.Cordova = cordova;
};
if(!window.plugins) window.plugins = {};
window.plugins.barcodeScanner = new BarcodeScanner();
});发布于 2012-05-09 12:58:13
太棒了,
这个插件现在又起作用了。
一个问题是插件的文档仍然说Cordova.plist中的关键应该是org.apache.cordova.barcodeScanner,但是很明显,现在它应该是com.cordova.barcodeScanner。
发布于 2013-01-20 20:12:07
我刚在cordova 2.3中添加了barcodescanner -这很简单
复制必要的文件后,只需将以下行添加到config.xml
<plugin name="org.apache.cordova.barcodeScanner" value="CDVBarcodeScanner" /> https://stackoverflow.com/questions/10450259
复制相似问题