经常有功能需求 从相册中发送一个二维码 然后直接识别当前二维码
代码如下
//判断是否是二维码
UIImage *srcImage =imageView.image;
CIContext *context = [CIContext contextWithOptions:nil];
CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:context options:@{CIDetectorAccuracy:CIDetectorAccuracyHigh}];
CIImage *image = [CIImage imageWithCGImage:srcImage.CGImage];
NSArray *features = [detector featuresInImage:image];
CIQRCodeFeature *feature = [features firstObject];
NSString *result = feature.messageString;
if (result == 0) {
//没有扫描到二维码
}
else{
//存在二维码
}