我尝试使用以下代码扫描图像中的QR码。 基本上我的问题是“prepareQRCodeDetector”返回nil(至少在iPhone 5s上,还没有在另一台设备上测试)
请注意,CIDetectorTypeFace返回一个正常工作的CIDetector。
在文档中,据说该功能可从iOS 8获得
//iOS CoreImage QR Detector
- (CIDetector *) prepareQRCodeDetector {
return [CIDetector detectorOfType:CIDetectorTypeQRCode context:nil options:@{CIDetectorAccuracy: CIDetectorAccuracyHigh}];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
if (image != nil){
//AVFoundation QRCode detection
CIImage *ciImage = [[CIImage alloc] initWithCGImage:image.CGImage options:nil];
NSString * decodedAccountName = @"";
CIDetector * detector = [self prepareQRCodeDetector];
if (detector != nil) {
NSArray<CIFeature*> *features = [detector featuresInImage:ciImage];
for (id feature in features) {
decodedAccountName = ((CIQRCodeFeature *)feature).messageString;
}
[self openUserProfileByAccountName:decodedAccountName];
}
}
[picker dismissViewControllerAnimated:YES completion:nil];
}