Dynamsoft Barcode Reader SDK 10.4.2000 FOR IOS

打印 上一主题 下一主题

主题 880|帖子 880|积分 2640

iOS 条形码解码用户指南

要求



  • 支持的操作系统:iOS 11或更高版本(发起使用iOS 13及更高版本)。
  • 支持的 ABI:arm64x86_64
  • 开发环境:Xcode 13 及以上版本(发起 Xcode 14.1+)。


有三种方法可以将 SDK 添加到您的项目中 -手动、通过CocoaPods或通过Swift 包管理器
选项 1:通过 Swift 包管理器添加 xcframeworks


  • 在您的 Xcode 项目中,转到文件 –> AddPackages
  • 在窗口的右上角,搜刮“https://github.com/Dynamsoft/barcode-reader-spm”
  • 选择barcode-reader-spm、选择Exact version、输入10.4.2000,然后单击添加包
  • 查抄所有xcframeworks并添加。
选项 2:通过 CocoaPods 添加框架


  • 在您的Podfile中添加框架,TargetName并用您的真实目标名称替换。
               
    1. target 'HelloWorld' do
    2.    use_frameworks!
    3. pod 'DynamsoftBarcodeReaderBundle','10.4.2000'
    4. end
    复制代码
                 了解有关DynamsoftBarcodeReaderBundle模块的更多信息
  • 实行 pod 命令安装框架并天生工作区([TargetName].xcworkspace):
               
    1. pod install
    复制代码
选项 3:添加本地 xcframeworks 文件


  • 从Dynamsoft 官网下载 SDK 包,解压后在Dynamsoft\Frameworks目次下可以找到以下xcframeworks
  • 将xcframeworks拖放到您的 Xcode 项目中。确保查抄Copy items if needed并将Create groups框架复制到您的项目文件夹中。
  • 点击项目设置,然后转到常规 –> 框架、库和嵌入内容。将上述所有xcframeworks的嵌入字段设置为嵌入并署名
构建您的第一个应用步伐

在本节中,让我们创建一个HelloWorld应用步伐,用于从摄像机视频输入读取条形码。
   条记:
  

  • 本指南使用 XCode 14.2。
  • 您可以从HelloWorld/DecodeWithCameraEnhancerObjc Sample下载完整的 Objective-C 源代码
  • 您可以从HelloWorld/DecodeWithCameraEnhancer Sample下载完整的 Swift 源代码
  • 以下指南中使用 DCE 举行相机捕获。如果您使用 iOS AVFoundation 框架举行相机捕获,请检察DecodeWithAVCaptureSession 示例,了解怎样将条形码扫描添加到您的应用。
  创建新项目


  • 打开 Xcode 并选择创建一个新项目。
  • 选择iOS > App作为您的应用步伐。
  • 输入您的产物名称(DBRHelloworld)、界面(StoryBoard)并选择语言(Objective-C/Swift)。
  • 单击下一步按钮并选择保存项目的位置。
  • 单击创建按钮完成。
包罗框架

将 SDK 添加到您的新项目中。有几种方法可以做到这一点,本节将具体介绍所有这些方法。
初始化许可证

Dynamsoft Barcode Reader 必要有效的许可证才气运行。

  • LicenseVerificationListener通过ViewController类实现协议:

    •                     
      1. import DynamsoftLicense
      2. class ViewController: UIViewController, LicenseVerificationListener
      复制代码
       
  • 在方法中添加以下代码来初始化许可证application:didFinishLaunchingWithOptions:并接收回调消息:

    •                     
      1. func setLicense() {
      2.    LicenseManager.initLicense("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9", verificationDelegate: self)
      3. }
      4. func onLicenseVerified(_ isSuccess: Bool, error: Error?) {
      5.    if !isSuccess {
      6.       if let error = error {
      7.          print("\(error.localizedDescription)")
      8.       }
      9.    }
      10. }
      复制代码
              条记:
       

    • 许可证要发挥作用,必要网络连接。
    • 此处的许可证字符串将授予您限时试用许可证。
    • 您可以通过哀求试用许可证链接申请 30 天的试用许可证。
    • 如果您下载安装包,它默认附带 30 天的试用许可证。
       
设置相机增强器


  • 导入文件中必要的所有标题ViewController。

    •                     
      1. import DynamsoftCameraEnhancer
      2. import DynamsoftCaptureVisionRouter
      3. import DynamsoftBarcodeReader
      4. import DynamsoftCore
      复制代码
       
  • 初始化CameraEnhancer并CameraView添加的设置CameraEnhancer。

    •                     
      1. var cameraView:CameraView!
      2. let dce = CameraEnhancer()
      3. ...
      4. func setUpCamera() {
      5.    cameraView = .init(frame: view.bounds)
      6.    cameraView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
      7.    view.insertSubview(cameraView, at: 0)
      8.    dce.cameraView = cameraView
      9. }
      复制代码
       
通过 CaptureVisionRouter 设置条码解码使命


  • 初始化CaptureVisionRouter并与CameraEnhancer实例绑定。

    •                     
      1. let cvr = CaptureVisionRouter()
      2. ...
      3. func setUpDCV() {
      4.    try! cvr.setInput(dce)
      5. }
      复制代码
       
  • 实现onDecodedBarcodesReceived接收条形码解码结果,并将此结果接收器添加到当前 CVR 对象。

    •                     
      1. /**Add CapturedResultReceiver to your ViewController.*/
      2. class ViewController: UIViewController, CapturedResultReceiver, LicenseVerificationListener {
      3.    ...
      4.    func setUpDCV() {
      5.       ...
      6.       /**Add your CaptureResultReceiver to the CaptureVisionRouter.*/
      7.       cvr.addResultReceiver(self)
      8.    }
      9.    /**Implement onDecodedBarcodesReceived method of CaptureResultReceiver to receive the barcode decoding results.*/
      10.    func onDecodedBarcodesReceived(_ result: DecodedBarcodesResult) {
      11.       if let items = result.items, items.count > 0 {
      12.          DispatchQueue.main.async {
      13.             self.cvr.stopCapturing()
      14.          }
      15.          var message = ""
      16.          for item in items {
      17.             message = String(format:"\nFormat: %@\nText: %@\n", item.formatString, item.text)
      18.          }
      19.          showResult("Results", message) {
      20.             self.cvr.startCapturing(PresetTemplate.readBarcodes.rawValue)
      21.          }
      22.       }
      23.    }
      24.    private func showResult(_ title: String, _ message: String, completion: @escaping () -> Void) {
      25.       DispatchQueue.main.async {
      26.          let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
      27.          alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { _ in completion() }))
      28.          self.present(alert, animated: true, completion: nil)
      29.       }
      30.    }
      31. }
      复制代码
       
设置 viewDidLoad、viewWillAppear、viewWillDisappear

viewDidLoad现在已经定义和设置了所有紧张功能,让我们通过完成、viewWillAppear和功能来完成代码方面的工作viewWillDisappear。
   

  •               
    1. override func viewDidLoad() {
    2.    super.viewDidLoad()
    3.    /**Do any additional setup after loading the view.*/
    4.    setLicense()
    5.    setUpCamera()
    6.    setUpDCV()
    7. }
    8. override func viewWillAppear(_ animated: Bool) {
    9.    dce.open()
    10.    // Start capturing when the view will appear. If success, you will receive results in the CapturedResultReceiver. Otherwise you will receive the error message in a dialog.
    11.    cvr.startCapturing(PresetTemplate.readBarcodes.rawValue) { isSuccess, error in
    12.       if (!isSuccess) {
    13.          if let error = error {
    14.             self.showResult("Error", error.localizedDescription)
    15.          }
    16.       }
    17.    }
    18.    super.viewWillAppear(animated)
    19. }
    20. override func viewWillDisappear(_ animated: Bool) {
    21.    dce.close()
    22.    cvr.stopCapturing()
    23.    super.viewWillDisappear(animated)
    24. }
    25. ...
    复制代码
  设置相机权限

将隐私 - 相机使用阐明添加到info.plist您的项目以哀求相机权限。一种简朴的方法是访问您的项目设置,转到信息,然后将此隐私属性添加到 iOS 目标属性列表。
iOS 12 或更低版本的其他步骤

如果你的iOS版本低于13,请添加以下额外步骤:

  • 从文件中删除方法application:didDiscardSceneSessions:和。application:configurationForConnectingSceneSessionptions:AppDelegate
  • 删除SceneDelegate.Swift文件(SceneDelegate.h&SceneDelegate.m表示 Objective-C)。
  • 从您的 info.plist 文件中删除Application Scene Manifest。
  • 在您的文件中声明窗口AppDelegate.Swift(AppDelegate.h对于 Objective-C)。

    •                     
      1. import UIKit
      2. @main
      3. class AppDelegate: UIResponder, UIApplicationDelegate {
      4.    var window: UIWindow?
      5. }
      复制代码
       
运行项目


  • 选择要在其上运行应用的设备。请留意,您必要一个物理设备来运行该应用步伐。如果您在模拟器上运行该应用步伐,您将在运行时遇到一些错误,由于必要物理相机组件。如果您有 M1 Macbook(或更高型号),您可以直接在 Macbook 上运行该应用步伐,由于它具有与您的 iPhone/iPad 类似的架构。
  • 运行该项目,然后您的应用步伐将安装在您的设备上。
您可以在此处下载完整的源代码:


  • Objective-C 源代码
  • Dynamsoft Barcode Reader

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

河曲智叟

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表