I want to scan qr and bar codes both from live camera and from image. I previously used ZBar library to scan codes. It doesn't scan specific types of qr and bar codes. Also Apple's AVFoundation framework seems like more fast and accurate while scanning codes from live camera.
So I don't want to use ZBar. In order to scan code from images picked from gallery I'm using CIDetector. But there seems like CIDetector can't scan bar codes from images. I have searched all over stack over flow CIDetector For other Barcode Types , Scanning barcode from UIImage natively (i.e., not using ZBar)
but I haven't found a way to scan bar codes form images picked from gallery using CIDetector. Is it possible to scan barcodes from UIImages using CIDetector ?
Don't suggest other third party library. I want to use apple's default framework to do the job.
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
[picker dismissViewControllerAnimated:YES completion:nil];
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
CIImage *img = [[CIImage alloc]initWithImage:image];
CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:nil options:@{CIDetectorAccuracy:CIDetectorAccuracyHigh}];
if (detector)
{
NSArray* featuresR = [detector featuresInImage:img];
NSString* decodeR;
for (CIQRCodeFeature* featureR in featuresR)
{
NSLog(@"decode %@ ",featureR.messageString);
decodeR = featureR.messageString;
[self showAlertWithTitle:@"Success" withMessage:decodeR];
return;
}
[self showAlertWithTitle:@"Error" withMessage:@"Invalid Image"];
}
}
Till now apple's AVFoundation Framework does not provide a way to scan bar codes picked from image library.
So I solved my issue by using AVFoundation Framework for scanning QR and Bar code in live camera, whereas when user pics photos from gallery I use ZBar Framework to scan qr and bar codes.