Directly on the code, there is no more nonsense.
VIEWCONTROLLER.M//QRCode////Created by Chenchen on 15/7/30. Copyright (c) 2015 BSY.
All rights reserved. #import <AVFoundation/AVFoundation.h> #import "ViewController.h" @interface Viewcontroller () < avcapturemetadataoutputobjectsdelegate> @end @implementation Viewcontroller-(void) viewdidload {[Super Viewdi
Dload];
Avcapturesession *session = [[Avcapturesession alloc] init];
Avcapturedevice *device = [Avcapturedevice defaultdevicewithmediatype:avmediatypevideo];
Nserror *error = nil; Avcapturedeviceinput *input = [avcapturedeviceinput deviceinputwithdevice:device error
:&error];
if (input) {[Session addinput:input];
else {NSLog (@ "error:%@", error);
} avcapturemetadataoutput *output = [[Avcapturemetadataoutput alloc] init]; Sets the encoding format supported by the sweep code (set bar code and two-dimensional code compatible below) [Output Setmetadataobjecttypes:@[avmetadataobjecttypeqrcode, Avmetadataobjecttypeean13code, AvmetadataobjecttypeEan8code, Avmetadataobjecttypecode128code]];
[Output Setmetadataobjectsdelegate:self queue:dispatch_get_main_queue ()];
[Session Addoutput:output];
[Session startrunning];
} #pragma mark-avcapturemetadataoutputobjectsdelegate-(void) Captureoutput: (Avcaptureoutput *) captureoutput Didoutputmetadataobjects: (Nsarray *) metadataobjects fromconnection: (avcaptureconnection *) connection {NSString *QRC
Ode = nil; For (Avmetadataobject *metadata in metadataobjects) {if ([Metadata.type Isequaltostring:avmetadataobjecttypeqrcode]) {//This'll never happen nobody has ever scanned a QR code ... ever qrcode = [(avmetadatamachinereadablecod
Eobject *) metadata stringvalue];
Break
} NSLog (@ "QR Code:%@", QRCode);
}-(void) didreceivememorywarning {[Super didreceivememorywarning];
Dispose of any of the can is recreated.
} @end