iOS 系统识别相册里面的二维码
2021-03-18 本文已影响0人
晴朗Nic
///系统识别相册二维码
+(NSString *)stringValueFrom:(UIImage *)image{
///系统识别二维码
CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:nil options:@{CIDetectorAccuracy: CIDetectorAccuracyHigh}];
// 取得识别结果
NSArray *features = [detector featuresInImage:[CIImage imageWithCGImage:image.CGImage]];
NSString *resultStr;
if (features.count == 0) {
return @"请检查图片是不是二维码";
}
for (int index = 0; index < [features count]; index ++) {
CIQRCodeFeature *feature = [features objectAtIndex:index];
resultStr = feature.messageString;
}
return resultStr;
}