随笔 - 65  文章 - 0  评论 - 21  阅读 - 32万

【iOS QR Code】集成ZXingWidget(XCode Version 4.5.2,iOS 6.0 SDK)

 

1、添加ZXingWidget

打开目录ZXing/iphone/ZXingWidget,将ZXingWidget.xcode文件拖拽添加到项目中

 

2、设置Link Binary With Libraries

TARGETS -> Build Phases -> Link Binary With Libraries

点击+,添加libZXingWidget.a

 

3、设置Target Dependencies

TARGETS -> Build Phases -> Target Dependencies

点击+,添加ZXingWidget

 

4、设置Header Search Paths

TARGET -> Build Settings -> Search Paths -> Header Search Paths

添加ZXing/iphone/ZXingWidget/Classes相对路径,选择recursive

添加ZXing/cpp/core/src相对路径,选择non-recursive

 

5、导入iOS框架

TARGETS -> Build Phases -> Link Binary With Libraries

点击+,添加AVFoundation、AudioToolbox、CoreVideo、CoreMedia、libiconv、AddressBook和AddressBookUI

 

6、测试

ViewController.h

复制代码
#import <UIKit/UIKit.h>
#import <ZXingWidgetController.h>
#import <QRCodeReader.h>

@interface ViewController : UIViewController <ZXingDelegate>

- (IBAction)scan:(id)sender;

@end
复制代码

 

将ViewController.m重命名为ViewController.mm

复制代码
#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)scan:(id)sender {
    ZXingWidgetController *widController = [[ZXingWidgetController alloc] initWithDelegate:self showCancel:YES OneDMode:NO];
    QRCodeReader* qrcodeReader = [[QRCodeReader alloc] init];
    NSSet *readers = [[NSSet alloc ] initWithObjects:qrcodeReader,nil];
    [qrcodeReader release];
    widController.readers = readers;
    [readers release];
    NSBundle *mainBundle = [NSBundle mainBundle];
    widController.soundToPlay =
    [NSURL fileURLWithPath:[mainBundle pathForResource:@"beep-beep" ofType:@"aiff"] isDirectory:NO];
    [self presentModalViewController:widController animated:YES];
    [widController release];
}

#pragma mark -
#pragma mark ZXingDelegate
- (void)zxingController:(ZXingWidgetController *)controller didScanResult:(NSString *)result {
    [self dismissModalViewControllerAnimated:YES];
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"结果" message:result delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alertView show];
    [alertView release];
}

- (void)zxingControllerDidCancel:(ZXingWidgetController *)controller {
    [self dismissModalViewControllerAnimated:YES];
}

@end
复制代码

 

Build,报了1个错:'iostream' file not found

解决方案:

重命名main.m为main.mm

重命名AppDelegate.m为AppDelegate.mm

 

再Build,报了31个错:Undefined symbols for architecture i386

解决方案:

参考:

http://stackoverflow.com/questions/12665457/zxing-in-xcode-4-5-and-ios-6

自己创建的项目:

TARGETS -> Build Settings -> Apple LLVM compiler 4.1 - Language

设置C++ Standard Library的值为Compiler Default

ZXingWidget项目:

TARGETS -> Build Settings -> Architectures

设置Architectures的值为Standard(armv7, armv7s)

 

 

posted on   Anthony Li  阅读(4806)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
< 2012年12月 >
25 26 27 28 29 30 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

博客园博客已停止更新,博客地址:dyinigbleed.com

点击右上角即可分享
微信分享提示