gpt4 book ai didi

swift - 如何在 Swift 项目中导入 Zbar Framework

转载 作者:搜寻专家 更新时间:2023-10-31 22:36:19 24 4
gpt4 key购买 nike

我有一个项目,目前正在尝试转换为 Swift 项目,但我不知道如何展示一个从相机源扫描的 Zbar 条形码阅读器。在我当前的项目中,我这样调用

- (IBAction)scanButton:(id)sender {

// ADD: present a barcode reader that scans from the camera feed
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;

ZBarImageScanner *scanner = reader.scanner;
// TODO: (optional) additional reader configuration here

// EXAMPLE: disable rarely used I2/5 to improve performance
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];

// present and release the controller
[self presentViewController:reader animated:YES completion:nil];}

注意:到目前为止我做了什么

  1. 将框架复制到swift中
  2. 将框架路径添加到 header 搜索路径(目标部分 > build设置)

    • $(PROJECT_DIR)/Test/ZBarSDK/Headers/ZBarSDK
    • 为桥接创建了 Projectname-Bridging-Header.h(添加了来自 zbar 的所有 h 文件)
    • 将 Projectname-Bridging-Header.h 添加到 header 搜索路径

在那之后,如果我写“import ZBarSDK”或 ZBarReaderDelegate 仍然给我错误!

最佳答案

对于 swift 3:

extension ZBarSymbolSet: Sequence {
public func makeIterator() -> NSFastEnumerationIterator {
return NSFastEnumerationIterator(self)
}
}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
// ADD: get the decode results
let results: NSFastEnumeration = info[ZBarReaderControllerResults] as! NSFastEnumeration

var symbolFound : ZBarSymbol?

for symbol in results as! ZBarSymbolSet {
symbolFound = symbol as? ZBarSymbol
break
}
let resultString = symbolFound!.data
print(resultString)
}

关于swift - 如何在 Swift 项目中导入 Zbar Framework,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26138773/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com