第三方)
ZBarSDK
----------------------------------------------------------------
(Main.storyboard)
Label,UIImageView,UIButton
----------------------------------------------------------------
(View.m)
#import "ZBarSDK 2/Headers/ZBarSDK/ZBarSDK.h"
@interface ViewController ()
连线:
@property (weak, nonatomic) IBOutlet UILabel *showLabel;
@property (weak, nonatomic) IBOutlet UIImageView *showImgView;
- (IBAction)scanQRImage:(id)sender;
-------------------------------------
viewDidLoad
-------------------------------------
- (IBAction)scanQRImage:(id)sender {
//实例化一个扫描控制器
ZBarReaderViewController*readVc=[[ZBarReaderViewController alloc]init];
//设置代理
readVc.readerDelegate=self;
//获取控制器中的扫描器对象
ZBarImageScanner*scanner=readVc.scanner;
//设置扫描其实别的图片类型
[scanner setSymbology:ZBAR_I25 config:ZBAR_CFG_ENABLE to:0];
//控制器跳转
[self presentViewController:readVc animated:YES completion:nil];
}
#pragma make------ZBarReaderViewDelegate------
//获取多媒体信息(图片、二维码、视频)回调的方法
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)Info{
//
[picker dismissViewControllerAnimated:YES completion:nil];
//获取
UIImage*img=[Info objectForKey:UIImagePickerControllerOriginalImage];
// //将二进制转换为图片
// UIImage*img=[UIImage imageWithData:imgData];
//将图片显示在图像视图
self.showImgView.image=img;
/*获取扫描得到的二维码图片信息*/
//得到扫描到的图片信息数据集合
id<NSFastEnumeration>results=[Info objectForKey:ZBarReaderControllerResults];
//获取集合中的信息
ZBarSymbol*symbol=nil;
for (symbol in results) {
}if (symbol==nil) {
NSLog(@"扫描失败");
return;
}
//如果不为空获取扫描到的结果
NSString*resStr=symbol.data;
//把数据展示在label上
self.showLabel.text=resStr;
//
if ([symbol.data hasPrefix:@"http://"] || [symbol.datahasPrefix:@"https://"]) {
NSURL*url=[NSURL URLWithString:symbol.data];
[[UIApplication sharedApplication]openURL:url options:nilcompletionHandler:nil];
}
}
----------------------------------------------------------------
( app.h)
#import
@interface AppDelegate : UIResponder
@property (strong, nonatomic) UIWindow *window;
@property (readonly, strong) NSPersistentContainer *persistentContainer;
- (void)saveContext;
----------------------------
(info.plist)
+
Privacy - Camera Usage Description Value:打开相机
+Localization native development region
-----------------------------------------
(数据库)
libiconv.tbd
QuartzCore.framework
CoreVideo.framework
CoreMedia.framework
AVFoundation.framework
libzbar.a
网友评论