IOS to achieve two-dimensional code scanning function _ios

Source: Internet
Author: User

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

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.