开发者社区> 问答> 正文

phonegap2.9 启动 barcodescanner ios:报错

我运用phonegap在ios那边调用barcodescanner,达到二维码扫描的功能.

但是我是全部都设置好了,却还是无法启动,后来是barcodescanner这个js文件我是换了又换才勉强启动了

但是这个换好了的文件还是会有问题,虽然启动了,所以想说请各位指教下,哪里的问题.

上代码:

(这是现在用的)


 /**
 * cordova is available under *either* the terms of the modified BSD license *or* the
 * MIT License (2008). See  http://opensource.org/licenses/alphabetical for full text.
 *
 * Copyright (c) Matt Kane 2010
 * Copyright (c) 2011, IBM Corporation
 */


/**
 * I was not able to get PhoneGap.define/require to work
 * but it worked fine when I switched it to cordova.define/require
 * ymmv
 */
//PhoneGap.define("cordova/plugin/BarcodeScanner",
cordova.define("cordova/plugin/BarcodeScanner",
               
               function (require, exports, module) {
               
               var exec = require("cordova/exec");
               
               var BarcodeScanner = function () {
               };
               
               //-------------------------------------------------------------------
               BarcodeScanner.Encode = {
               TEXT_TYPE: "TEXT_TYPE",
               EMAIL_TYPE: "EMAIL_TYPE",
               PHONE_TYPE: "PHONE_TYPE",
               SMS_TYPE: "SMS_TYPE",
               //  CONTACT_TYPE: "CONTACT_TYPE",  // TODO:  not implemented, requires passing a Bundle class from Javascript to Java
               //  LOCATION_TYPE: "LOCATION_TYPE" // TODO:  not implemented, requires passing a Bundle class from Javascript to Java
               };
               
               //-------------------------------------------------------------------
               BarcodeScanner.prototype.scan = function (successCallback, errorCallback) {
               if (errorCallback == null) {
               errorCallback = function () {
               }
               }
               
               if (typeof errorCallback != "function") {
               console.log("BarcodeScanner.scan failure: failure parameter not a function");
               return
               }
               
               if (typeof successCallback != "function") {
               console.log("BarcodeScanner.scan failure: success callback parameter must be a function");
               return
               }
               
               exec(successCallback, errorCallback, 'BarcodeScanner', 'scan', []);
               };
               
               //-------------------------------------------------------------------
               BarcodeScanner.prototype.encode = function (type, data, successCallback, errorCallback, options) {
               if (errorCallback == null) {
               errorCallback = function () {
               }
               }
               
               if (typeof errorCallback != "function") {
               console.log("BarcodeScanner.scan failure: failure parameter not a function");
               return
               }
               
               if (typeof successCallback != "function") {
               console.log("BarcodeScanner.encode failure: success callback parameter must be a function");
               return
               }
               
               exec(successCallback, errorCallback, 'BarcodeScanner', 'encode', [
                                                                                 {"type": type, "data": data, "options": options}
                                                                                 ]);
               };
               
               var barcodeScanner = new BarcodeScanner();
               module.exports = barcodeScanner;
               });

//我想更换的barcodescanner文件是这样的

 /**
 * cordova is available under *either* the terms of the modified BSD license *or* the
 * MIT License (2008). See  http://opensource.org/licenses/alphabetical for full text.
 *
 * Copyright (c) Matt Kane 2010
 * Copyright (c) 2011, IBM Corporation
 */

var ScannerLoader = function (require, exports, module) {
    
    var exec = require("cordova/exec");
    
    /**
     * Constructor.
     *
     * @returns {BarcodeScanner}
     */
    function BarcodeScanner() {
        
        /**
         * Encoding constants.
         *
         * @type Object
         */
        this.Encode = {
        TEXT_TYPE: "TEXT_TYPE",
        EMAIL_TYPE: "EMAIL_TYPE",
        PHONE_TYPE: "PHONE_TYPE",
        SMS_TYPE: "SMS_TYPE"
            //  CONTACT_TYPE: "CONTACT_TYPE",  // TODO:  not implemented, requires passing a Bundle class from Javascript to Java
            //  LOCATION_TYPE: "LOCATION_TYPE" // TODO:  not implemented, requires passing a Bundle class from Javascript to Java
        };
        
        /**
         * Barcode format constants, defined in ZXing library.
         *
         * @type Object
         */
        this.format = {
            "all_1D": 61918,
            "aztec": 1,
            "codabar": 2,
            "code_128": 16,
            "code_39": 4,
            "code_93": 8,
            "data_MATRIX": 32,
            "ean_13": 128,
            "ean_8": 64,
            "itf": 256,
            "maxicode": 512,
            "msi": 131072,
            "pdf_417": 1024,
            "plessey": 262144,
            "qr_CODE": 2048,
            "rss_14": 4096,
            "rss_EXPANDED": 8192,
            "upc_A": 16384,
            "upc_E": 32768,
            "upc_EAN_EXTENSION": 65536
        };
    };
    
    /**
     * Read code from scanner.
     *
     * @param {Function} successCallback This function will recieve a result object: {
     *        text : '12345-mock',    // The code that was scanned.
     *        format : 'FORMAT_NAME', // Code format.
     *        cancelled : true/false, // Was canceled.
     *    }
     * @param {Function} errorCallback
     */
    BarcodeScanner.prototype.scan = function (successCallback, errorCallback) {
        if (errorCallback == null) {
            errorCallback = function () {
            };
        }
        
        if (typeof errorCallback != "function") {
            console.log("BarcodeScanner.scan failure: failure parameter not a function");
            return;
        }
        
        if (typeof successCallback != "function") {
            console.log("BarcodeScanner.scan failure: success callback parameter must be a function");
            return;
        }
        
        exec(successCallback, errorCallback, 'BarcodeScanner', 'scan', []);
    };
    
    //-------------------------------------------------------------------
    BarcodeScanner.prototype.encode = function (type, data, successCallback, errorCallback, options) {
        if (errorCallback == null) {
            errorCallback = function () {
            };
        }
        
        if (typeof errorCallback != "function") {
            console.log("BarcodeScanner.encode failure: failure parameter not a function");
            return;
        }
        
        if (typeof successCallback != "function") {
            console.log("BarcodeScanner.encode failure: success callback parameter must be a function");
            return;
        }
        
        exec(successCallback, errorCallback, 'BarcodeScanner', 'encode', [
                                                                          {"type": type, "data": data, "options": options}
                                                                          ]);
    };
    
    var barcodeScanner = new BarcodeScanner();
    module.exports = barcodeScanner;
    
}

ScannerLoader(require, exports, module);

cordova.define("cordova/plugin/BarcodeScanner", ScannerLoader); 

//然后调用是这样的

var scanner = window.cordova.require("cordova/plugin/BarcodeScanner");
    scanner.scan(
                 function (result) {
                  alert(result);
                 },
                 function (error) {
                    alert(error);
                 }
                 );


//但是我实际想调用的是这样的

window.plugins.barcodeScanner.scan(
    function(result) {
        if (result.cancelled)
            alert("the user cancelled the scan")
        else
            alert("we got a barcode: " + result.text)
    },
    function(error) {
        alert("scanning failed: " + error)
    }
)
但是却无法调用,能请各位看看是哪里的问题么?

我在config.xml那里已经设置好了的,其余的地方也添加了的.但是为什么调用会失败呢?

<feature name="BarcodeScanner">
        <param name="ios-package" value="CDVBarcodeScanner" />
</feature>



展开
收起
kun坤 2020-06-14 10:54:17 534 0
1 条回答
写回答
取消 提交回答
  • 输出这些信息:

    DEPRECATION NOTICE: The Connection ReachableViaWWAN return value of '2g' is deprecated as of Cordova version 2.6.0 and will be changed to 'cellular' in a future release. 

    ******************************************************* 

     WARNING: -[<AVCaptureVideoPreviewLayer: 0x15500ea0> isOrientationSupported] is deprecated.  Please use AVCaptureConnection's -isVideoOrientationSupported

    *******************************************************

     WARNING: -[<AVCaptureVideoPreviewLayer: 0x15500ea0> setOrientation:] is deprecated.  Please use AVCaptureConnection's -setVideoOrientation: 




    2020-06-14 10:54:26
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
手淘iOS性能优化探索 立即下载
From Java/Android to Swift iOS 立即下载
深入剖析iOS性能优化 立即下载

相关实验场景

更多