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

【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
复制代码

转载于:https://www.cnblogs.com/skyry/p/5114596.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值