Solve the problem of failing to identify the QR code picture from the album

The problem encountered in reading the QR code in the album with the CIDetector class is that the pictures taken from the mobile phone screen can be read successfully, and the success rate of taking out pictures taken by the mobile phone is low. And does not support reading barcodes.

Solution : Read the QR code / barcode in the photo album and use ZBarSDK . Here's how to introduce ZBarSDK into the project . Because my Demo project does not use CocoaPods to manage third-party libraries, I introduce manually import ZBarSDK into the project and configure it.


Step 1. Create a Frameworks folder in the project and import the ZBarSDK folder, as shown in the figure



Step two . Add dependent libraries in the project, as shown:


Step three . Import header file and calls the corresponding method.

#import "ZBarSDK.h"

/**
 * Get the QR code image in the album
 */
-(void)getQRcodeImage {     // ZBarsSDK initializes     ZBarReaderController *imagePicker = [ZBarReaderController new];     imagePicker.showsHelpOnFail = NO; // Prohibit the display of failed reading pages     imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;     imagePicker.delegate = self;     imagePicker.allowsEditing = YES;     [self presentViewController:imagePicker animated:YES completion:nil]; } /**  * Callback for selected picture  */ -(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {     id<NSFastEnumeration> results = [info objectForKey:ZBarReaderControllerResults];
    




    














    
    ZBarSymbol *symbol = nil;
    
    for(symbol in results) {         break;     }     [picker dismissViewControllerAnimated:YES completion:^{         //QR code string         NSString *QRCodeString = symbol.data;         // trigger callback         [self getScanDataString:QRCodeString] ; }]; } /**  * Failed to read QR code/Barcode callback  */ -(void)readerControllerDidFailToRead:(ZBarReaderController *)reader withRetry:(BOOL)retry{     if (retry) {//retry == 1 Select the picture as a non-QR code.         [self dismissViewControllerAnimated:YES completion:^{             [self getScanDataString:@"No QR code/barcode found"];         }];     }     return; }
        


    

        


        


        








    


            


        


    



以上是我实际开发中找到的最快速解决读取相册中二维码失败的方法,也是对原文链接的精简版处理。希望对大家有帮助


分享ZBarSDK的下载地址

原文链接:http://blog.csdn.net/gaomingyangc/article/details/54017879



Guess you like

Origin blog.csdn.net/niumanxx/article/details/79300634