如何在我自己的应用程序中集成二维码阅读器



我正在开发一个应用程序,我需要在其中添加二维码阅读器功能,应该是这样的,我需要主页上有一个图标,点击图标QR reader应该可以工作。我在谷歌上搜索了一下,发现ZBarCoderReader很好用,但我在集成这个SDK时遇到了麻烦。有人能帮助集成这个SDK吗。我知道我必须使用下面的链接来集成这个SDK。http://zbar.sourceforge.net/iphone/sdkdoc/install.htmlhttp://zbar.sourceforge.net/iphone/sdkdoc/camera.html

如有任何帮助,我们将不胜感激。

  • 1.从此链接下载ZBar SDK
  • 2.打开dmg并将ZBarSDK文件夹复制到您的project directory
  • 3.在XCode中右键单击您的项目并选择"将文件添加到您的项目名称",然后添加ZBarSDK framework
  • 4.现在转到Build Phases并展开Link Binary With Libraries,然后添加以下附加框架
    • AVFoundation.framework
    • CoreMedia.framework
    • CoreVideo.framework
    • QuartzCore.framework
    • libiconv.dylib

然后

导入头文件

#import "ZBarSDK.h"

在图标按钮的触摸上添加以下代码:

- (IBAction)iconButtonTouchEvent:(id)sender {
    ZBarReaderViewController *reader = [ZBarReaderViewController new];
    reader.readerDelegate = self;
    reader.supportedOrientationsMask = ZBarOrientationMaskAll;
    //Hide Info Button at Right bottom and Show only Cancel Button at Left Bottom
    float currentVersion= 5.1;
    float sysVersion = [[[UIDevice currentDevice]systemVersion]floatValue];
    UIView * infoButton;
    if (sysVersion > currentVersion) {
        infoButton = [[[[[reader.view.subviews objectAtIndex:1] subviews] objectAtIndex:0] subviews] objectAtIndex:3];
     }
     else {
        infoButton = [[[[[reader.view.subviews objectAtIndex:1] subviews] objectAtIndex:0] subviews] objectAtIndex:2];
     }
    [infoButton setHidden:YES];
    ZBarImageScanner *scanner = reader.scanner;
    [scanner setSymbology: ZBAR_I25 config: ZBAR_CFG_ENABLE to: 0];
    [self presentModalViewController: reader animated: YES];
}
#pragma mark - Barcode Delegate Methods
- (void)imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info{
    id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
    ZBarSymbol *symbol = nil;
    for(symbol in results)
        break;
    NSLog(@"Barcode Data = %@", symbol.data);
    [reader dismissModalViewControllerAnimated: YES];
}

示例项目

相关内容

最新更新