How to import Zbar Framework in Swift Project

三世轮回 提交于 2020-01-02 07:09:10

问题


I have a project and currently trying to convert to Swift project but I couldn't figure out how to present a Zbar barcode reader that scans from the camera feed. On my current project I called like this

- (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];}

Note: What I did so far

  1. Copy framework into the swift
  2. Added framework path to the Header Search Paths (Targets Section > Build Settings)

    • $(PROJECT_DIR)/Test/ZBarSDK/Headers/ZBarSDK
    • Created Projectname-Bridging-Header.h for Bridging (added all h files from zbar)
    • Added Projectname-Bridging-Header.h to Header Search Paths

After that either if I write "import ZBarSDK" or ZBarReaderDelegate still gives me error!


回答1:


for 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)
    }



回答2:


Here is the solution

following link helped me https://stackoverflow.com/a/24005242/4059179

But after that I had NSEnumeration Problem so here second problem solution

func imagePickerController(picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [NSObject : AnyObject]){
var results: NSFastEnumeration = info[ZBarReaderControllerResults] as NSFastEnumeration
} 

Don't forget to extend

extension ZBarSymbolSet: SequenceType { public func generate() -> NSFastGenerator { return NSFastGenerator(self) } 
}



回答3:


I have this project

Using cocoapods to import the ZBarSDK to Swift 2.0 project.



来源:https://stackoverflow.com/questions/26138773/how-to-import-zbar-framework-in-swift-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!