iOS 原生识别二维码

//长按事件

-(void)longShowImageAction:(UILongPressGestureRecognizer *)sender{

UIImageView * disImageView = (UIImageView *)sender.view;

if (disImageView.image) {

//1. 初始化扫描仪,设置设别类型和识别质量

CIDetector*detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:nil options:@{ CIDetectorAccuracy : CIDetectorAccuracyHigh }];

//2. 扫描获取的特征组

NSArray *features = [detector featuresInImage:[CIImage imageWithCGImage:disImageView.image.CGImage]];

//3. 获取扫描结果

CIQRCodeFeature *feature = [features objectAtIndex:0];

NSString *scannedResult = feature.messageString;

DBLog(@"扫描到的结果  %@",scannedResult);

//如果扫描到的结果是url,这里是直接在浏览器中打开扫描的url,如果不是,可以判断一下,让去做其他的事情

[[UIApplication sharedApplication]openURL:[NSURL URLWithString:scannedResult]];

}

}

你可能感兴趣的:(iOS 原生识别二维码)