Start a Project

Swift QR Code Scanner & Generator

Hi Guys , Are you searching for a quick QR code scanner and generator now here is the one. This post will tell you about…

How to generate and scan a QR code using this fabulous library named 

SwiftQRCode

Its available on Github https://github.com/liufan321/SwiftQRCode

Install the library using CocoaPods and follow these steps and rest will happen itself .

To scan a QR code :- 

  1. Import SwiftQRCode
  2. Create an object of QRCode class.
  3. Provide the scan frame on which your camera will open to scan the QR code into ViewDidLoad
  4. Call the prepareScan method into ViewDidLoad which will return a closure with scanned information from the QR code
  5. Into your viewDidAppear method call the startScan method to start scanning the QR code.

Don’t forget to request for NSCameraUsageDescription in the info.plist

The above code will start your camera into your given scan frame and return the encoded information as String into the prepare scan closure.

To generate a QR code :-

  1. GenerateImage method in the QRCode class will generate the QRCode and set it as a image into your imageView’s image.

The method includes three parameters.

  1. Message to be encode.
  2. avatarImage the avatar(watermark) image over your QR code
  3. avatarScale to provide the scaling to avatar image.

Now you can easily generate and scan the QRCode and save your development time.

SEE YA ….

Exit mobile version