1

I'm creating an app for mac which needs to create QR barcodes as a part of the application.

I've found https://github.com/jverkoey/ObjQREncoder for iOS but couldn't to make it work on my Mac application.

Is there any libraries for generating QR barcodes in Objective-C on Mac?

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
Shahin
  • 865
  • 6
  • 21

2 Answers2

5

You can try use CIFilter to generate QRCode :

static func generateQRCode(from string: String) -> NSImage? {
    let data = string.data(using: String.Encoding.ascii)

    if let filter = CIFilter(name: "CIQRCodeGenerator") {
        filter.setValue(data, forKey: "inputMessage")
        let transform = CGAffineTransform(scaleX: 3, y: 3)

        if let output = filter.outputImage?.applying(transform) {
            let rep = NSCIImageRep(ciImage: output)
            let nsImage = NSImage(size: rep.size)
            nsImage.addRepresentation(rep)
            return nsImage
        }
    }
    return nil
}
isaced
  • 1,735
  • 3
  • 16
  • 24
3

The QR & bar code encoding and decoding library you're looking for is this (which I've used in a couple of my own projects):

http://github.com/TheLevelUp/ZXingObjC

It's a full Objective-C port of the ZXing image processing library. When you build it, it creates both iOS and MacOS targets (frameworks and libraries).

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • I just tried it. works for every barcode types, but returns nil on QRcode! both result and error is empty. here's my code: – Shahin Apr 15 '13 at 19:22
  • Sounds like this is a different question. Why not create a new question and include your code? – Michael Dautermann Apr 15 '13 at 19:42
  • :) sure. Thanks, here's my question: http://stackoverflow.com/questions/16024161/creating-qr-barcodes-with-zxingobjc-on-mac – Shahin Apr 15 '13 at 20:28