Scan QR Code From Gallery Swift

Updated 6 January 2018


Hi Guyz , Hope you guyz have implemented QR Code functionality into your project on which we have discussed in my last post.

If not then visit :-


Now , after scanning and generating the code , sometimes we need to scan the code from the image in our iOS photo library. This feature doesn’t require any third party library as its available in AVFoundation.

AV Foundation is the full featured framework for working with time-based audiovisual media on iOS, macOS, watchOS and tvOS. Using AV Foundation, you can easily play, create, and edit QuickTime movies and MPEG-4 files, play HLS streams, and build powerful media functionality into your apps.

To scan a code from the image available in gallery Follow these steps:-

  1. import AVFoundation in your ViewController class
  2. Now assign UIImagePickerControllerDelegate and UINavigationControllerDelegate to get the image from gallery.
  3. Get your image from the image gallery and detect the QRCode using CIDetecter

CIDetecter is an image processor that identifies notable features (such as faces and barcodes) in a still image or video.

Your overall code will be :-

Lets dive into the code we have just implemented inside the delegate function

  1. We have created an instance of CIDetecter of type QRCode

2. Converted the selected image into CIImage

3. Detect the encoded information from the image using the detecter.

4. Now the qrCodeLink is the String which represents the decoded information from the QRCode (a message or may be a url).

That all Folks , now you have the decoded information from the image containing your QRCode.

Enjoy and comment if you have any issue.




. . .

Leave a Comment

Your email address will not be published. Required fields are marked*

Be the first to comment.

Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home