QR Code scan for iOS

Source: Internet
Author: User

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

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.