对于我正在从事的项目,必须有一种扫描二维码的方法。我从 phonegap-plugin-barcodescanner 得到了这个.事实上,它在 Android 上运行良好,从未出现过任何问题。
但在 iO 上它会按原样崩溃。您将收到使用相机的请求,然后应用程序崩溃。我发现解决这个问题的方法是删除它的选项部分,然后它就可以工作了。
这看起来有点奇怪的解决方法。 问题:有没有更好的办法解决这个问题?
cordova.plugins.barcodeScanner.scan(
function (result) {
alert("We got a barcode\n" +
"Result: " + result.text + "\n" +
"Format: " + result.format + "\n" +
"Cancelled: " + result.cancelled);
},
function (error) {
alert("Scanning failed: " + error);
},
{
"preferFrontCamera" : true, // iOS and Android
"showFlipCameraButton" : true, // iOS and Android
"prompt" : "Place a barcode inside the scan area", // supported on Android only
"formats" : "QR_CODE,PDF_417", // default: all but PDF_417 and RSS_EXPANDED
"orientation" : "landscape" // Android only (portrait|landscape), default unset so it rotates with the device
}
);
使用:Windows 10、Intel XDK v3619、Cordova CLI 6.2.0 和 phonegap-plugin-barcodescanner 4.1.0
最佳答案
我也遇到过通过 Phonegap Build 在 IOS 10 上使用 cordova-plugin-barcodescanner 的崩溃问题。
经过数小时的尝试,现在解决了,我必须先添加 cordova-plugin-camera,然后再添加 cordova-plugin-barcodescanner。
这是我工作的 config.xml 的相关摘录:
<meta http-equiv="Content-Security-Policy" content="default-src * gap: file:; style-src 'self' 'unsafe-inline'; img-src 'self' data: gap:; script-src * 'unsafe-inline' 'unsafe-eval'">
<plugin name="cordova-plugin-camera" spec="~2.3.1">
<variable name="CAMERA_USAGE_DESCRIPTION" value="My App would like to access your camera, to take photos of your documents." />
</plugin>
<preference name="android-build-tool" value="gradle" />
<plugin name="cordova-plugin-barcodescanner">
<variable name="CAMERA_USAGE_DESCRIPTION" value="abc123" />
</plugin>
在 Android6 和 IOS10 上,GitHub 的示例现在运行良好:https://github.com/phonegap/phonegap-plugin-barcodescanner
关于javascript - Phonegap 插件 barcodescanner 在 iOs 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40256725/