国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > iOS > 正文

iOS實(shí)現(xiàn)二維碼的掃描功能

2019-10-21 18:57:36
字體:
供稿:網(wǎng)友
本文給大家介紹的是iOS 原生態(tài)API實(shí)現(xiàn)二維碼的掃描功能,非常簡單實(shí)用,有需要的小伙伴可以參考下。
 

直接上代碼,就不多廢話了

//// 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 viewDidLoad];          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];  //設(shè)置掃碼支持的編碼格式(如下設(shè)置條形碼和二維碼兼容)  [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 *)captureOutputdidOutputMetadataObjects:(NSArray *)metadataObjects    fromConnection:(AVCaptureConnection *)connection{  NSString *QRCode = nil;  for (AVMetadataObject *metadata in metadataObjects) {    if ([metadata.type isEqualToString:AVMetadataObjectTypeQRCode]) {      // This will never happen; nobody has ever scanned a QR code... ever      QRCode = [(AVMetadataMachineReadableCodeObject *)metadata stringValue];      break;    }  }     NSLog(@"QR Code: %@", QRCode);}- (void)didReceiveMemoryWarning {  [super didReceiveMemoryWarning];  // Dispose of any resources that can be recreated.} @end
 


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到IOS開發(fā)頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 白玉县| 上思县| 沁源县| 罗城| 太仓市| 呼图壁县| 抚州市| 田阳县| 阳泉市| 印江| 汽车| 甘肃省| 红原县| 商水县| 定远县| 黄骅市| 洛南县| 三明市| 长顺县| 台州市| 娱乐| 周口市| 连州市| 孝感市| 阳曲县| 福贡县| 谷城县| 五华县| 东乡| 正定县| 怀仁县| 民和| 资源县| 阜新市| 赤峰市| 五指山市| 呼和浩特市| 隆安县| 新平| 杭锦旗| 启东市|