如何使用Dynamsoft iOS相机SDK

几周前,Dynamsoft发布了一个iOS相机SDK,旨在帮助开发人员快速构建适用于iOS平台的文档扫描应用。 在本文中,我将分享如何在Xcode中配置SDK,以及如何从头开始创建简单的文档扫描器应用程序。

  • 适用于iOS 1.0的Dynamsoft Camera SDK
  • Xcode 9.2
  • 迅捷4.0

在使用SDK之前,您最好了解不同类之间的关系。

打开Xcode,然后按Shift + Command + N创建一个Single View App。

在Xcode中构建项目时,出现以下错误:

这是StackOverflow的解决方案:

  1. 关闭Xcode。
  2. 打开钥匙链。
  3. 在本地中找到iOS开发者证书。
  4. 将证书从“本地”拖放到“系统”选项卡。
  5. 出现提示时输入管理员密码。
  6. 启动Xcode并为您的设备构建项目。

DynamsoftCameraSDK.framework拖到您的项目中。 确保选中“如果需要复制项目”。

该SDK取决于sqlite3stdc ++ 。 单击项目设置>常规 ,添加libsqlite3.tbdlibstdc ++。tbd

如果要使用视频视图实时扫描文档,请单击项目设置>信息以添加“隐私-相机使用说明”。

如果没有此属性,则会收到错误消息:

 2018-02-02 15:55:08.511904+0800 docscanner[4310:948418] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles 2018-02-02 15:55:08.511904+0800 docscanner[4310:948418] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles 2018-02-02 15:55:08.512628+0800 docscanner[4310:948418] [MC] Reading from public effective user settings. 2018-02-02 15:55:08.665667+0800 docscanner[4310:948447] [access] This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSCameraUsageDescription key with a string value explaining to the user how the app uses this data. (lldb) 

还有一个步骤-单击项目设置>构建设置>其他链接器标志以添加’-ObjC’。

没有此标志,您将得到如下错误:

  2018-02-02 16:11:59.018002+0800 docscanner[4416:964122] +[UIImage getImageFromeDcsResourceBundleWithName:]: unrecognized selector sent to class 0x1b676db58 2018-02-02 16:11:59.023812+0800 docscanner[4416:964122] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[UIImage getImageFromeDcsResourceBundleWithName:]: unrecognized selector sent to class 0x1b676db58' 

创建一个桥接头文件docscanner-Bridging-Header.h

  #ifndef Bridging_Header_h #import  #import  #import  #import  #import  #import  #import  #import  #import  #endif /* Bridging_Header_h */ 

选择ViewController.swift 。 在viewDidLoad()函数中,创建一个DcsView作为根视图:

  dcsView = DcsView.self.init(frame:CGRect.init(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height)) view.addSubview(dcsView) dcsView = DcsView.self.init(frame:CGRect.init(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height)) view.addSubview(dcsView) 

到目前为止,已经完成了一个简单的文档扫描器应用程序。 您无需在情节提要上创建任何UI元素。 默认情况下,DcsView将显示一个图片库。 如果要打开照相机以扫描文档,请将当前视图更改为视频视图:

  dcsView.currentView = DVE_VIDEOVIEW dcsView.videoView.mode = DME_DOCUMENT 

视频视图上有一个取消按钮和一个捕获按钮。 您可以通过触摸其他视图来导航至其他视图:

  dcsView.videoView.nextViewAfterCancel = DVE_IMAGEGALLERYVIEW dcsView.videoView.nextViewAfterCapture = DVE_EDITORVIEW 

另外,您可以创建一个按钮来触发视图更改:

  openVideoViewButton = UIButton(frame:CGRect(x:self.view.center.x-100, y:self.view.center.y-20, width: 200, height: 40)) openVideoViewButton.setTitle("Back to Camera", for : .normal) openVideoViewButton.setTitleColor(UIColor.blue, for : .normal) openVideoViewButton.setTitle("Back to Camera", for : .normal) openVideoViewButton.setTitleColor(UIColor.blue, for : .normal) openVideoViewButton.addTarget(self, action:#selector(onClick), for :UIControlEvents.touchUpInside); openVideoViewButton.setTitleColor(UIColor.blue, for : .normal) openVideoViewButton.addTarget(self, action:#selector(onClick), for :UIControlEvents.touchUpInside); dcsView.imageGalleryView.addSubview(openVideoViewButton);  @objc func onClick(){ dcsView.currentView = DVE_VIDEOVIEW } 

生成并运行iOS文档扫描仪。

Dynamsoft iOS Camera SDK还提供UI资源。

DynamsoftCameraSDKResource.bundle拖到您的项目中。 确保选中“如果需要复制项目”。

生成并重新运行该项目。 现在,您可以看到触摸按钮和相机的图标。

https://developer.dynamsoft.com/dws/ios-edition

https://github.com/yushulx/ios-document-scanner


最初于 2018年2月12日 发布在 www.codepool.biz