demo下载:http://download.csdn.net/download/qingsi00/5001589
如今二维码随处可见,无论是实物商品还是各种礼券都少不了二维码的身影。
而手机等移动设备又成为二维码的一个很好的应用平台,不管是生成二维码还是扫码二维码。
下面介绍一下如何在苹果iOS设备上使用二维码:
然后在使用的地方引入头文件
#import "ZBarSDK.h"
调用ZBar的类必须实现ZBarReaderDelegate协议
如:UIViewController <ZBarReaderDelegate>
源文件如下:
- (BOOL) application: (UIApplication*) application
didFinishLaunchingWithOptions: (NSDictionary*) options
{
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
// force class to load so it may be referenced directly from nib
[ZBarReaderViewController class];
ZBarReaderViewController *reader =
[self.tabBarController.viewControllers objectAtIndex: 0];
reader.readerDelegate = self;
reader.showsZBarControls = NO;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
return(YES);
}
// ZBarReaderDelegate
- (void) imagePickerController: (UIImagePickerController*) picker
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
// do something useful with results
UITabBarController *tabs = self.tabBarController;
tabs.selectedIndex = 1;
ResultsViewController *results = [tabs.viewControllers objectAtIndex: 1];
UIImage *image = [info objectForKey: UIImagePickerControllerOriginalImage];
results.resultImage.image = image;
id <NSFastEnumeration> syms =
[info objectForKey: ZBarReaderControllerResults];
for(ZBarSymbol *sym in syms) {
results.resultText.text = sym.data;
break;
}
}
2. 生成二维码(编码)
设置头文件路径,在TARGET中building settings Search Path
当然也可以直接将库编译成静态库libQREcoder.a然后在包含进来接着在Frameworks 中添加静态库的引用
注意demo中还没有生成二维码的代码,稍后加上。
demo下载: http://download.csdn.net/download/qingsi00/5001589