Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[移动]一个移动端扫码插件(二维码、条形码等) #6

Open
songhlc opened this issue Jul 1, 2016 · 0 comments
Open

Comments

@songhlc
Copy link
Owner

songhlc commented Jul 1, 2016

最近手头上正在开发的app需要用到扫码功能,于是上用上了这一个cordova的插件目前来说适配ios以及安卓的效果还不错。推荐下大家尝试使用。

  • 关于cordova
    这就不去详细描述里,参考[cordova官网](http://cordova.apache.org/
  • 关于barcodescanner
    插件地址
  • 如何使用
    1. 通过npm安装corodva并在本地创建一个cordova工程,并添加platform:android/ios
    2. cordova plugin add phonegap-plugin-barcodescanner
    3. 核心代码:
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
      }
   );
4. 注意事项:scan方法需要在deviceReady之后调用
     document.addEventlisterner('deviceready',onDeviceReady,false);
     function onDeviceReady(){
           //here bind event to click to use camera to scan barcode
     }

html中需要通过script引入cordova.js(执行cordova build android之后在asserts目录下就能找到对应的文件)

  • 如果需要把文件放倒服务器端进行加载,请确保拷贝的文件包含以下目录:cordova-js-src 不同平台生成的对应文件不一样,请进行确认(build后自动生成的文件)
@songhlc songhlc changed the title [] [移动]phonegap 扫码 插件(二维码、条形码等) Jul 1, 2016
@songhlc songhlc changed the title [移动]phonegap 扫码 插件(二维码、条形码等) [cordova-plugin]一个移动端扫码插件(二维码、条形码等) Jul 1, 2016
@songhlc songhlc changed the title [cordova-plugin]一个移动端扫码插件(二维码、条形码等) [移动]一个移动端扫码插件(二维码、条形码等) Jul 1, 2016
@songhlc songhlc changed the title [移动]一个移动端扫码插件(二维码、条形码等) [移动]一个移动端扫码插件(二维码、条形码等) Jul 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant