Generate two-dimensional code
Prerequisites: you need to import the following code
1. Define a Uiimageview attribute in the Viewcontroller. m file, storing the QR code
@property (Weak, nonatomic) Iboutlet Uiimageview *imageview;
2. Write the following code in the Viewdidload method
Self.imageView.image = [Qrcodegenerator qrimageforstring:@ "Huan Huan" imageSize:self.imageView.frame.size.width];
QR Code Scan: On the real machine can
Prerequisites: need to introduce a system framework
#import <AVFoundation/AVFoundation.h>
1. Defining attributes
@property (nonatomic, strong) avcapturesession *capturesession;
2. Write the following code in Viewdidload
Self.capturesession = [[Avcapturesession alloc] init];
Customizing the Camera Interface
Avcapturedevice *device = [Avcapturedevice Defaultdevicewithmediatype:avmediatypeaudio];
Avcapturedeviceinput *input = [Avcapturedeviceinput deviceinputwithdevice:device error:nil];
Set the input stream for the session
[_capturesession Addinput:input];
Set the output stream of the session
Avcapturemetadataoutput *output = [[Avcapturemetadataoutput alloc] init];
To set the proxy for the output stream
[OutPut setmetadataobjectsdelegate:self Queue:dispatch_get_main_queue ()];
Set the type of sweep code
[_capturesession Addoutput:output];
Two-dimensional code and human face
[OutPut Setmetadataobjecttypes:@[avmetadataobjecttypeqrcode, Avmetadataobjecttypeface]];
Creating a camera coating
Avcapturevideopreviewlayer *layer = [Avcapturevideopreviewlayer layerWithSession:self.captureSession];
Layer.frame = Self.view.bounds;
[Self.view.layer Addsublayer:layer];
Start scanning
[Self.capturesession startrunning];
Two-dimensional code