Search code examples
iosswiftcore-graphicsswift4qr-code

How to set QRCode version in Swift 4


Using the Core Graphic library I'm able to generate almost any types of . QR-Code, however, I have no control over the version being used by Swift.

According to http://www.qrcode.com/en/about/version.html there are several versions, which are

current code:

let filter = CIFilter(name: "CIQRCodeGenerator")
filter?.setValue(vcard, forKey: "inputMessage")
filter?.setValue("M", forKey: "inputCorrectionLevel")

if let output = filter?.outputImage {
  let scaleX = qrCode.frame.size.width / output.extent.size.width
  let scaleY = qrCode.frame.size.height / output.extent.size.height
  let transform = CGAffineTransform(scaleX: scaleX, y: scaleY)
  let scaledOutput = output.transformed(by: transform)
  self.qrCode.image = UIImage(ciImage: scaledOutput)
}

does not let me control the version of the qr-code being used. It only makes sure that the resulting image is not blurred and this is it.

Is there a way, as for the correction level, to pass qr-code version to the Core Image lib?


Solution

  • As per the documentation.

    Generates an output image representing the input data according to the ISO/IEC 18004:2006 standard.

    Which I believe is version 2. Version 3 is the ISO/IEC 18004:2015 standard. There is no way to change the QR version according to the docs.