Took inspiration from https://gist.github.com/wszdwp/205dcccbf096c21f6288
You can refer to this as an updated verion of https://gist.github.com/wszdwp/205dcccbf096c21f6288
Took inspiration from https://gist.github.com/wszdwp/205dcccbf096c21f6288
You can refer to this as an updated verion of https://gist.github.com/wszdwp/205dcccbf096c21f6288
use_frameworks! | |
pod 'ZBarSDK' |
protocol ScanViewControllerDelegate: NSObjectProtocol { | |
func scanViewController(scanViewController: ScanViewController, didFindBarcode barcode: String) | |
} | |
extension ZBarSymbolSet: SequenceType { | |
public func generate() -> NSFastGenerator { | |
return NSFastGenerator(self) | |
} | |
} | |
class ScanViewController: ZBarReaderViewController, ZBarReaderDelegate { | |
weak var delegate: ScanViewControllerDelegate? | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.readerDelegate = self | |
self.supportedOrientationsMask = 0 | |
self.readerView.zoom = 1.0 | |
self.modalInPopover = false | |
self.showsZBarControls = false | |
self.scanner.setSymbology(ZBAR_UPCA, config: ZBAR_CFG_ENABLE, to: 1) | |
} | |
// MARK: - ZBarReaderDelegate | |
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { | |
let results: NSFastEnumeration = info[ZBarReaderControllerResults] as! NSFastEnumeration | |
var symbolFound : ZBarSymbol? | |
for symbol in results as! ZBarSymbolSet { | |
symbolFound = symbol as? ZBarSymbol | |
break | |
} | |
delegate?.scanViewController(self, didFindBarcode: String(symbolFound!.data)) | |
} | |
} |