ios - 条形码扫描器在 ios 中第一次使用时卡住,而在第二次单击时它工作正常

标签 ios cordova phonegap-plugins

您好,我正在使用 phonegap barcodeplugin wildabeast/BarcodeScanner 扫描条形码。

这是我的代码

$('#scanbtn').on( "tap", function(evt){

                    scanner = null;

                    if(ival == 0){
                        ival = 1;
                        scanaction();

                    }

            });

            function scanaction(){
                cordova.plugins.barcodeScanner.scan( function (result) {

                        scanText = result.text;
                        scanFormat = result.format;
                        scanCancelled = result.cancelled;

                    /* alert("We got a barcode\n" +
                                "Result: " + scanText + "\n" +
                                "Format: " + scanFormat + "\n" +
                                "Cancelled: " + scanCancelled); */

                                $.mobile.changePage('#pageTwo',{transition: "slide"});


                    }, function (error) {
                        ival = 0;
                        console.log("Scanning failed: ", error);

                    });
            }

This is the screen I'm getting on the first scan,and the scanner goes stuck,and not scanning anymore

这次我得到的日志是

    2014-05-23 10:41:26.629 ShareQ[283:60b] WARNING: -[<AVCaptureVideoPreviewLayer: 0x155ba090> isOrientationSupported] is deprecated.  Please use AVCaptureConnection's -isVideoOrientationSupported
    2014-05-23 10:41:26.735 ShareQ[283:60b] WARNING: -[<AVCaptureVideoPreviewLayer: 0x155ba090> setOrientation:] is deprecated.  Please use AVCaptureConnection's -setVideoOrientation:
    2014-05-23 10:41:27.300 ShareQ[283:60b] WARNING: -[<AVCaptureVideoPreviewLayer: 0x155ba090> setOrientation:] is deprecated.  Please use AVCaptureConnection's -setVideoOrientation:
    2014-05-23 10:41:27.310 ShareQ[283:60b] Warning: Attempt to present <CDVbcsViewController: 0x155392f0> on <MainViewController: 0x1559e3c0> while a presentation is in progress!
    2014-05-23 10:41:27.321 ShareQ[283:60b] Warning: Attempt to present <CDVbcsViewController: 0x1553bb20> on <MainViewController: 0x1559e3c0> while a presentation is in progress!
    2014-05-23 10:41:27.324 ShareQ[283:60b] Warning: Attempt to present <CDVbcsViewController: 0x1553d2b0> on <MainViewController: 0x1559e3c0> while a presentation is in progress!
    2014-05-23 10:41:27.326 ShareQ[283:60b] Warning: Attempt to present <CDVbcsViewController: 0x155418b0> on <MainViewController: 0x1559e3c0> while a presentation is in progress!
    2014-05-23 10:41:27.328 ShareQ[283:60b] Warning: Attempt to present <CDVbcsViewController: 0x155456f0> on <MainViewController: 0x1559e3c0> while a presentation is in progress!
    2014-05-23 10:41:27.331 ShareQ[283:60b] Warning: Attempt to present <CDVbcsViewController: 0x155fa710> on <MainViewController: 0x1559e3c0> while a presentation is in progress!

最佳答案

问题是由于jquerymobile框架。 jquerymobile 中的“tap”功能在单击时多次触发是我提到的问题的原因。通过如下更改 jquerymobile 的“tap”方法来纠正此问题

    $(document).off('tap', '#scanbtn')
                          .on('tap', '#scanbtn',function(e) {
                                   if(ival == 0){
                                          ival = 1;
                                          scanaction();

                                    }

                             });

现在我的问题已经解决了。扫描仪工作正常。

关于ios - 条形码扫描器在 ios 中第一次使用时卡住,而在第二次单击时它工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23821807/

相关文章:

java - 启动相机 Activity Cordova 插件

ios - 我在 AppDelegate 中添加 Root View 处理程序时出错

ios - 错误检查无法正常用于解析查询

iOS app 首次运行用户教程

ios - 使用 UITabController 时将数据传递到 UIViewController 的一般方法

ios - 在我的 XCode 项目中找不到 Cordova.plist

android - 有什么方法可以在基于 HTML 的移动应用程序中使用 Flash?

java - Phonegap 构建错误 : Failed to run "javac -version", 确保您安装了 JDK

Android Phonegap 构建屏幕分辨率问题

ios - phonegap-plugin-push 不适用于 iOS 9