I am trying to give the user of my app the ability to take an image from their library and scan the QRCode from it. Here is the relevant code:
This is the function that returns from the Image Picker with the selected image.
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
let thisImage:CIImage? = CIImage(image: image)
let code = performQRCodeDetection(thisImage!)
self.dismissViewControllerAnimated(true, completion: nil)
self.performSegueWithIdentifier("goBackSegue", sender: code)
}
Inside that function I call this function to do the QRCode scanning:
func performQRCodeDetection(image: CIImage) -> String {
var decode = ""
let options = [CIDetectorAccuracy: CIDetectorAccuracyHigh]
let detector = CIDetector(ofType: CIDetectorTypeQRCode, context: nil, options: options)
let features = detector.featuresInImage(image)
for feature in features as! [CIQRCodeFeature] {
decode = feature.messageString
}
return decode
}
The variable features always comes back empty. The image definitely has a QRCode in it. I took the image from all orientations and sizes. I cannot get any results.
Any thoughts?
Thanks!