支持Xcode6 IOS使用ZBar二维码扫描开发(解决arm64,arm7s兼容并解决中文乱码问题)

iOS7,AVFoundation中现在已经内置支持一维和二维码的扫瞄,iOS6及之前的想要扫瞄二维码,还是需要添加第三方库ZXing和ZBar。为了统一开发,兼容所有版本,我们可以只使用ZBar开源框架,但是用最新SDK,会报错,我们必须先解决arm64,arm7s兼容和中文乱码问题。

ZBar官网:点击打开链接

一、解决arm64,arm7s兼容并解决中文乱码问题

解决这个问题,需要替换libzbar.a,这里就不给出方法,直接给出下载地址:点击打开链接。

下载完成之后,删除原来SDK包里的libzbar.a,换成和这个就好了。

二、导入ZBarSDK需要的framework

AVFoundation.framework
CoreMedia.framework
CoreVideo.framework
QuartzCore.framework
libiconv.dylib

三、代码编写:

ViewController.h 中导入#import "ZBarSDK.h"并继承 <ZBarReaderDelegate>协议

关键代码:

- (void) scan{
    ZBarReaderViewController *reader = [ZBarReaderViewController new];
    reader.readerDelegate = self;
    reader.supportedOrientationsMask = ZBarOrientationMaskAll;
    
    ZBarImageScanner *scanner = reader.scanner;
    // TODO: (optional) additional reader configuration here
    
    // EXAMPLE: disable rarely used I2/5 to improve performance
    [scanner setSymbology: ZBAR_I25
                   config: ZBAR_CFG_ENABLE
                       to: 0];
    
    // present and release the controller
    [self presentModalViewController: reader
                            animated: YES];

}

- (void) imagePickerController: (UIImagePickerController*) reader
 didFinishPickingMediaWithInfo: (NSDictionary*) info
{
    // ADD: get the decode results
    id<NSFastEnumeration> results =
    [info objectForKey: ZBarReaderControllerResults];
    ZBarSymbol *symbol = nil;
    for(symbol in results)
        // EXAMPLE: just grab the first barcode
        break;
    
    // EXAMPLE: do something useful with the barcode data
    resultText.text = symbol.data;
    
    // EXAMPLE: do something useful with the barcode image
    resultImage.image =
    [info objectForKey: UIImagePickerControllerOriginalImage];
    
    // ADD: dismiss the controller (NB dismiss from the *reader*!)
    [reader dismissModalViewControllerAnimated: YES];

}

原创文章,转载请注明!

你可能感兴趣的:(ios,xcode,barcode)