The production and scanning of iOS QR code

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.