Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of QR Code Generation and scanning in iOS third Party Framework

Shulou Source: shulou.com Published: 2022-06-03 09:47:30 10月03日 Update

This article mainly introduces the iOS third-party framework of QR code generation and scanning example analysis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian with you to understand.

The details are as follows

Import third-party frames libqrencode (generate QR code) and ZBarSDK (QR code scan)

Import header file

# import "QRCodeGenerator.h" # import "ZBarSDK.h" create two buttons click the event button to generate the QR code-(IBAction) erWeiMaBtn1: (id) sender {/ / set the picture box to store the QR code UIImageView * imgView = [[UIImageView alloc] initWithFrame:CGRectMake ((self.view.frame.size.width-200) / 2,100,200,200)]; / / display to the main view [self.view addSubview:self.imgView] / / use the third-party method to realize the desired QR code imgView.image = [QRCodeGenerator qrImageForString:@ "fool" imageSize:self.imgView.frame.size.width];}

Click the button 2 to scan the QR code

-(IBAction) erWeiMaBtn1: (id) sender {/ / set text field (set to global) _ textView = [[UITextView alloc] initWithFrame:CGRectMake ((self.view.frame.size.width-300) / 2,430,300,300) textContainer:nil]; / / set background color _ textView.backgroundColor = [UIColor blueColor]; / / add to the main view [self.view addSubview:self.textView]; ZBarReaderViewController * reader = [ZBarReaderViewController alloc] init]; reader.readerDelegate = self / / hide the bottom control button reader.showsZBarControls = YES; / / set the self-defined interface / / reader.cameraOverlayView = someView (this view can be defined by yourself, of course, you can also add a masked view by [reader.view addSubview:someView], so you can make the desired view effect) / / set the recognition range (the four parameters here are all the view scale ~ ~ Don't get it wrong (the ratio to the left, the ratio to the top, the ratio to the width, the ratio to the height) / / reader.scanCrop = CGRectMake (0,1Pol 1) / / set the identified parameter ZBarImageScanner * scanner = reader.scanner; [scanner setSymbology:ZBAR_I25 / / this parameter and to: the following parameters work together to determine the identified coding range, which can be adjusted according to the requirements to improve the recognition speed. Config:ZBAR_CFG_ENABLE to:0]; [self presentViewController:reader animated:YES completion:nil];} / / here is the delegated method-(void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info {id results = [info objectForKey: ZBarReaderControllerResults]; ZBarSymbol * symbol = nil; for (symbol in results) break; NSLog (@ "% @", symbol.data); / / print identified data / / set content _ textView.text = symbol.data / / [reader dismissModalViewControllerAnimated:YES];}

Note: fill in the whitelist of available camera scans in info.plist!

Thank you for reading this article carefully. I hope the article "sample Analysis of QR Code Generation and scanning in iOS third Party Framework" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: 2D QR code scale third party generation parameters buttons articles views frames examples analysis main view content method scope above two events value Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Redmi Huawei Shulou Technology Apple