iOS.QRCodeRecipe

Xamarin.iOS recipe to generate a QR code

View the Project on GitHub dannycabrera/iOS.QRCodeRecipe

This is a sample recipe for the Xamarin Recipe Cook-Off. This sample shows how to generate a QR code and display inside a UIImageView control.

Screenshot

QRCodeScreenshot

Code

The process to generate a QR code is relatively easy. All that is required is the message you want to encode and setting the error correction level. If you need a bit more information on the error correction levels check the QR code wiki page.

  1. Generate the QR code:

    var qrGen = new CIQRCodeGenerator ();
    qrGen.Message = NSData.FromString (textField.Text);
    qrGen.CorrectionLevel = CorrectionLevel.M.ToString();
    
  2. Render the image:

    var context = CIContext.FromOptions(null);
    var img = UIImage.FromImage (context.CreateCGImage (qrGen.OutputImage, qrGen.OutputImage.Extent));
    

Apple's Documentation:
https://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CoreImageFilterReference/Reference/reference.html#//apple_ref/doc/filter/ci/CIQRCodeGenerator