1 contains
#import <AVFoundation/AVFoundation.h>
2 Importing Avfoundation library files
1 #import "ViewController.h"2 #import<AVFoundation/AVFoundation.h>3 @interfaceViewcontroller () <AVCaptureMetadataOutputObjectsDelegate>4-(ibaction) Scan: (UIButton *) sender;5@property (strong,nonatomic) Avcapturedevice *device;6@property (strong,nonatomic) avcapturedeviceinput *input;7@property (strong,nonatomic) avcapturemetadataoutput *output;8@property (strong,nonatomic) avcapturesession *session;9@property (strong,nonatomic) Avcapturevideopreviewlayer *Preview;Ten @end One A @implementationViewcontroller - -- (void) Viewdidload { the [Super Viewdidload]; - //additional setup after loading the view, typically from a nib. - - } + -- (void) Setupcamera + { A //Device at_device =[Avcapturedevice Defaultdevicewithmediatype:avmediatypevideo]; - - //Input -_input =[Avcapturedeviceinput deviceInputWithDevice:self.device error:nil]; - - //Output in_output =[[Avcapturemetadataoutput alloc]init]; - [_output setmetadataobjectsdelegate:self queue:dispatch_get_main_queue ()]; to + //Session -_session =[[Avcapturesession alloc]init]; the [_session Setsessionpreset:avcapturesessionpresethigh]; * if([_session canAddInput:self.input]) $ {Panax Notoginseng [_session addInput:self.input]; - } the + if([_session canAddOutput:self.output]) A { the [_session addOutput:self.output]; + } - $ //Barcode Type Avmetadataobjecttypeqrcode $_output.metadataobjecttypes =@[avmetadataobjecttypeqrcode]; - - //Preview the_preview =[Avcapturevideopreviewlayer layerWithSession:self.session]; -_preview.videogravity =Avlayervideogravityresizeaspectfill;Wuyi_preview.frame =cgrectmake ( -, the,280,280); the[Self.view.layer InsertSublayer:self.preview Atindex:0]; - Wu - About //Start $ [_session startrunning]; - } - #pragmaMark Avcapturemetadataoutputobjectsdelegate -- (void) Captureoutput: (Avcaptureoutput *) captureoutput didoutputmetadataobjects: (Nsarray *) metadataobjects fromConnection :(Avcaptureconnection *) Connection A { +NSString *stringvalue =[[NSString alloc] init]; the - if(Metadataobjects.count >0) { $Avmetadatamachinereadablecodeobject *metadataobject = [metadataobjects objectatindex:0]; theStringValue =Metadataobject.stringvalue; the } the the [_session stoprunning]; -NSLog (@"%@", stringvalue); in[Self Dismissviewcontrolleranimated:yes completion:^{ theUialertview *alert =[[Uialertview Alloc]initwithtitle:nil the Message:stringvalue About Delegate: Nil theCancelbuttontitle:@"OK" the Otherbuttontitles:nil,nil]; the [alert show]; + }]; - } the-(ibaction) Scan: (UIButton *) Sender {Bayi [self setupcamera]; the}
Need to be perfected .....
QR Code scan for iOS