I am trying to save a QR code image that was generated in my app, and when doing so I am unable to get the underlying data so that I can save it.
The QR code is generated via CIFilter
s from a string, nothing special, like so:
if let filter = CIFilter(name: "CIQRCodeGenerator") {
//set the data to the contact data
filter.setValue(contactData, forKey: "inputMessage")
filter.setValue("L", forKey: "inputCorrectionLevel")
if let qrImage = filter.outputImage {
self.qrCode = UIImage(ciImage: codeImage)
}
}
}
And, I'm trying to get the image data to save it to the application documents by doing so:
let data = UIImagePNGRepresentation(self.qrCode)
But, it always returns nil
.
I understand the documentation saying that it can return nil if no underlying data is found,
but I am confused at how I can store this image that is generated if there is no underlying data?