Introduction: CIDetector can only identify two-dimensional code images, bar codes are not currently supported

Qr codes or barcodes in albums can be identified by using ZBarSDK third parties

Step 1: Import the SDK

pod 'ZBarSDK'.'~ > 1.3.1'
Copy the code

The second step:

Void openPhoto {//ZBarsSDK initializes ZBarReaderController *imagePicker = zBarReaderController.new; imagePicker.showsHelpOnFail = NO; / / prohibited display page read failure imagePicker. SourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; imagePicker.delegate = self; imagePicker.allowsEditing = YES; [self presentViewController:imagePicker animated:YES completion:nil]; } // imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey, id> *)info { id<NSFastEnumeration> results = [info objectForKey:ZBarReaderControllerResults]; ZBarSymbol *symbol = nil;for (symbol in results) {
       break; } [picker dismissViewControllerAnimated: YES completion: ^ {/ / scan code information nsstrings. * QRCodeString = symbol data; NSLog (@"QRCodeString = %@",QRCodeString); }]; } Note: If you want to use ZBarSDK to take photos to recognize the QR code and barcode can also be, just put - (void)openPhoto; In thesourceThe Type is changed to: imagePicker. SourceType = UIImagePickerControllerSourceTypeCamera; Can, but note: this way is a photo recognition, not a scan recognition;Copy the code

Reference: www.jianshu.com/p/7917e28f7…