Skip to content

Instantly share code, notes, and snippets.

@freak4pc
Created August 26, 2018 08:37
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save freak4pc/3f7ae2801dd8b7a068daa957463ac645 to your computer and use it in GitHub Desktop.
Save freak4pc/3f7ae2801dd8b7a068daa957463ac645 to your computer and use it in GitHub Desktop.
Detect text messages from QR code
extension UIImage {
func parseQR() -> [String] {
guard let image = CIImage(image: self) else {
return []
}
let detector = CIDetector(ofType: CIDetectorTypeQRCode,
context: nil,
options: [CIDetectorAccuracy: CIDetectorAccuracyHigh])
let features = detector?.features(in: image) ?? []
return features.compactMap { feature in
return (feature as? CIQRCodeFeature)?.messageString
}
}
}
@nayabbuttfp
Copy link

it does not work for iOS Simulator 14.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment