iOS中识别二维码信息

2020-01-22  本文已影响0人  杨闯
//1.创建一个二维码探测器
CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:nil options:@{CIDetectorAccuracy : CIDetectorAccuracyHigh}];
        
//2.探测二维码的特征
CIImage *ciImage = [CIImage imageWithCGImage:image.CGImage];
        NSArray *qrCodeFeatures = [detector featuresInImage:ciImage];
        
NSString *content = nil;
//3.对识别出来的CIQRCodeFeature 进行遍历,如果发现了二维码信息,则会把二维码信息赋值给content
for (CIQRCodeFeature *feature in qrCodeFeatures) {
    if ([feature isKindOfClass:[CIQRCodeFeature class]] && feature.messageString.length) {
          content = feature.messageString;
           break;
      }
}
上一篇下一篇

猜你喜欢

热点阅读