IOS QR Code scan

Source: Internet
Author: User

viewcontroller.m//CX QR code scan////Created by Ma C on 16/4/12.//Copyright? 2016 BJSXT. All rights reserved.//#import "ViewController.h" #import <AVFoundation/AVFoundation.h> @interface Viewcontroller () <AVCaptureMetadataOutputObjectsDelegate> @end @implementation viewcontroller-(void)    viewdidload {}-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (uievent *) event{//Create capture session    Avcapturesession * session = [[Avcapturesession alloc]init];    Add input device Avcapturedevice * device = [Avcapturedevice defaultdevicewithmediatype:@ "Avmediatypevideo"];    Avcapturedeviceinput * input = [avcapturedeviceinput deviceinputwithdevice:device error:nil];    [Session Addinput:input];    Add output data avcapturemetadataoutput * outputs = [[Avcapturemetadataoutput alloc]init];    [Output Setmetadataobjectsdelegate:self queue:dispatch_get_main_queue ()];    [Session Addoutput:output]; Tell the metadata type to be a two-dimensional code type//Note that the method will crash after add or the test requires a real machine a little trouble is not [output setmetadatAobjecttypes:@[avmetadataobjecttypeqrcode]];    Add Scan layer Avcapturevideopreviewlayer *layer = [Avcapturevideopreviewlayer layerwithsession:session];    Layer.frame = CGRectMake (10,20, Self.view.frame.size.width, 400);    [Self.view.layer Addsublayer:layer];        Start scanning [session startrunning];    The following method is appropriate when the operation//stop scanning//[session stoprunning]; Remove layer//[layer Removefromsuperlayer];} -(void) Captureoutput: (Avcaptureoutput *) captureoutput didoutputmetadataobjects: (Nsarray *) metadataobjects  Fromconnection: (avcaptureconnection *) connection{//metadataobjects for scanned data avmetadatamachinereadablecodeobject    * OBJC = [metadataobjects lastobject]; We want the result NSLog (@ "%@", Objc.stringvalue);} @end

IOS QR Code scan

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.