iOS PhoneGap 1.7.0 +条形码扫描插件问题 [英] iOS PhoneGap 1.7.0 + Barcode Scanning Plugin issue
问题描述
是否有人能获得用于PhoneGap的BarcodeScanning插件以在PhoneGap 1.7.0上工作?
Has anyone managed to get the BarcodeScanning plugin for PhoneGap to work on PhoneGap 1.7.0?
条形码扫描插件: https://github.com/phonegap/phonegap-plugins/tree/master/iOS/BarcodeScanner
问题是插件添加时未设置..
The issues is that the plugin is not getting set when its added..
当我调用"alert(window.plugins.barcodeScanner);"时,我得到以下信息:
I get the following when I call "alert(window.plugins.barcodeScanner);"
未定义"
我正在尝试找出插件无法添加的地方,并在我了解更多信息后更新问题.
I am trying to isolate the point where the plugin is failing to get added and will update the question once I know more..
在此先感谢任何可以提供帮助的人...
Thanks in advance for anyone who can help...
更新后的答案如下:
推荐答案
好的,因此,在经过一番摸索之后,并使用twitter PhoneGap插件作为示例,我设法使其正常运行!
OK so after a bit of poking around and using the twitter PhoneGap plugin as an example I managed to get it working!!
我以此为基础,因为在Twitter上可爱的人们更新了他们的插件以与PhoneGap 1.7.0配合使用!感谢上帝!
I used this as a basis for my approach because the lovely people at twitter updated their plugin to work with PhoneGap 1.7.0 thank god!!
Twitter PhoneGap插件: 这是更新的条形码扫描器.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();
});
这篇关于iOS PhoneGap 1.7.0 +条形码扫描插件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!