简体   繁体   中英

IOS can't read QR code on iphone5 or 4s, but 6, 6s are OK

I put the QR code in an UIImageView and use the system method to read it.
It works on iPhone6 or 6s but can't read anything on iPhone5.

Does anyone know how to fix it?

CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:nil options:@{ CIDetectorAccuracy : CIDetectorAccuracyHigh }];
NSArray *features = [detector featuresInImage:[CIImage imageWithCGImage:self.QRImageView.image.CGImage]];

Looks you'll need to use AVCaptureMetadataOutput .

// Device
self.device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

// Input
self.input = [AVCaptureDeviceInput deviceInputWithDevice:self.device error:nil]

// Output
self.output = [[AVCaptureMetadataOutput alloc] init];
[self.output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
self.output.metadataObjectTypes = @[AVMetadataObjectTypeQRCode];

// Session
self.session = [[AVCaptureSession alloc] init];
[self.session addInput:self.input];
[self.session addOutput:self.output];  

Other people have noted that CIDetector only works on the iPhone 5s and up, iPad Air and up.

(device reference: https://forums.developer.apple.com/thread/20887 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM