The production and scanning of iOS QR code
QR Code SDK Dome "QRCode" in the production of Libqrencode library files, scanning ZBARSDK library files
1. Make two-dimensional code/* character to two-dimensional code
Import Libqrencode File
Add #import "QRCodeGenerator.h"
@property (Strong, nonatomic) uiimageview* Qrimageview;
-(void) viewdidload
{
[Super Viewdidload];
Self.qrimageview = [[Uiimageview alloc] Initwithframe:cgrectmake (0, 0, 320, 400)];
[Self.view AddSubview:self.qRImageView];
}
-(Ibaction) Qrbtnpress: (ID) sender
{
Self.qRImageView.image = [qrcodegenerator qrimageforstring:@ "QR code stored string information ASDDSDD" ImageSize: Self.qRImageView.bounds.size.width];
}
2. Read QR code information
Add #import "ZBarSDK.h"//Read two-dimensional code library
@interface viewcontroller:uiviewcontroller//to read the two-dimensional code generation
@property (Strong, nonatomic) zbarreaderviewcontroller* reader;
@property (Strong, nonatomic) nsstring* Qrurl;
-(void) viewdidload
{
[Super Viewdidload];
Self.qrurl = [[NSString alloc] init];
Self.reader = [[Zbarreaderviewcontroller alloc] init];
Self.reader.readerDelegate = self;
Self.reader.supportedOrientationsMask = Zbarorientationmaskall;
Zbarimagescanner *scanner = Self.reader.scanner;
[Scanner setsymbology:zbar_i25
Config:zbar_cfg_enable
TO:0];
The main meaning given in this section for the ZBARSDK documentation is to initialize the object of the Zbarreaderviewcontroller class and to set the proxy callback method to-(void) Imagepickercontroller: ( uiimagepickercontroller*) Reader
Didfinishpickingmediawithinfo: (nsdictionary*) Info
Self.qrimageview = [[Uiimageview alloc] Initwithframe:cgrectmake (0, 0, 320, 400)];
[Self.view AddSubview:self.qRImageView];
}
The camera view required by the QR code will be scanned when the button is clicked, Self.reader is the object of the (Zbarreaderviewcontroller) class
-(Ibaction) Qrpress: (ID) sender
{
[Self PresentViewController:self.reader animated:yes completion:^{
NSLog (@ "FD");
}];
}
This callback method is fixed, as long as you know the following points are needed to extract the data from the Symbol.data, so it is necessary to declare a string in the. h file to accept the good. Here I declare the Self.qrurl object to be accepted in. h, and then just write it in the following format.
-(void) Imagepickercontroller: (uiimagepickercontroller*) reader
Didfinishpickingmediawithinfo: (nsdictionary*) Info
{
ID results =
[Info objectforkey:zbarreadercontrollerresults];
Zbarsymbol *symbol = nil;
for (symbol in results)
{
NSLog (@ "Symbol =%@", symbol.data);
Break
}
Self.qrurl = Symbol.data;
uialertview* alert = [[Uialertview alloc] initWithTitle:self.qRUrl message:self.qRUrl delegate:self cancelbuttontitle: @ "OK" otherbuttontitles:nil];
[Alert show];
Self.qRImageView.image =
[Info objectforkey:uiimagepickercontrolleroriginalimage];
[Self.reader Dismissviewcontrolleranimated:yes completion:^{
}];
}
The production and scanning of iOS QR code