说起IOS开发,我是个新手,最近公司接到的项目,C、C++都快忘光的我做IOS开发表示又很大的压力。无奈,还是的搞。找了找资料,看了几天就走在了IOS APP开发的道路上。
在做扫一扫功能,由于自己没有做过,还是比较迷茫,android的扫一扫是集成第三方的框架做的,比较简单几步就搞定了,但是IOS的扫一扫功能,现在来看也是很简单的。只不过第一次做,完全没有经验而已。我的扫一扫功能是使用LBXScan这个框架做的。如果你们以后要做这个功能,只是扫一扫得到二维码的code,那么用我下面说的方法即可。源码在下面。

1 我的开发环境

  • XCODE9.2
  • Cocoapods1.4.0
  • Objective-C

2 LBXScan下载地址

https://github.com/MxABC/LBXScan

3 集成使用步骤

3.1 创建项目

3.2 创建pod依赖管理文件

在项目根目录创建Podfile文件
注意没有用过Cocoapods请参考:
https://blog.csdn.net/ruyulin/article/details/79534032

3.3 编辑Podfile文件

platform :ios, ‘8.0’#Demo-LBXScan 是target目录名称,一般情况与项目名称相同的那个。
target 'Demo-LBXScan' do #扫一扫pod 'LBXScan/LBXNative','~> 2.3'pod 'LBXScan/LBXZXing','~> 2.3'pod 'LBXScan/LBXZBar','~> 2.3'pod 'LBXScan/UI','~> 2.3'pod 'LBXAlertAction', '~> 1.0.6'
end

3.3 在命令行进入项目跟目录进行进行依赖安装操作

witsystemdeMacBook-Pro:Demo-LBXScan witsystem$ ls
Demo-LBXScan        Demo-LBXScanTests   Podfile
Demo-LBXScan.xcodeproj  Demo-LBXScanUITests
witsystemdeMacBook-Pro:Demo-LBXScan witsystem$ pod install
Analyzing dependencies
Downloading dependencies
Installing LBXAlertAction (1.0.6)
Installing LBXScan (2.3)
Installing ZBarSDK (1.3.1)
Generating Pods project
Integrating client project[!] Please close any current Xcode sessions and use `Demo-LBXScan.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There are 5 dependencies from the Podfile and 3 total pods installed.[!] Smart quotes were detected and ignored in your Podfile. To avoid issues in the future, you should not use TextEdit for editing it. If you are not using TextEdit, you should turn off smart quotes in your editor of choice.

3.4 安装依赖后,项目截图

3.5 编译项目

使用command + b项目编译报错:

ld: warning: directory not found for option '-L/Users/witsystem/Library/Developer/Xcode/DerivedData/Demo-LBXScan-dtnxdyiagqhprgajvucupburjhlk/Build/Products/Debug-iphonesimulator/LBXAlertAction'
ld: warning: directory not found for option '-L/Users/witsystem/Library/Developer/Xcode/DerivedData/Demo-LBXScan-dtnxdyiagqhprgajvucupburjhlk/Build/Products/Debug-iphonesimulator/LBXScan'
ld: warning: directory not found for option '-L/Users/witsystem/Library/Developer/Xcode/DerivedData/Demo-LBXScan-dtnxdyiagqhprgajvucupburjhlk/Build/Products/Debug-iphonesimulator/ZBarSDK'
ld: library not found for -lLBXAlertAction
clang: error: linker command failed with exit code 1 (use -v to see invocation)

解决方式,请参考:
https://blog.csdn.net/ruyulin/article/details/79534032

3.6 创建PrefixHeader.pch文件

    ////  PrefixHeader.pch//  Restaurant////  Created by witsystem on 2018/3/21.//  Copyright © 2018年 witsystem. All rights reserved.//#ifndef PrefixHeader_pch#define PrefixHeader_pch// Include any system framework and library headers here that should be included in all compilation units.// You will also need to set the Prefix Header build setting of one or more of your targets to reference this file.//LBXScan 如果需要使用LBXScanViewController控制器代码,那么下载了那些模块,请定义对应的宏#define LBXScan_Define_Native  //包含native库#define LBXScan_Define_ZXing   //包含ZXing库#define LBXScan_Define_ZBar   //包含ZBar库#define LBXScan_Define_UI     //包含界面库#endif /* PrefixHeader_pch */

3.7 配置文件PrefixHeader.pch

3.8 添加权限

    <key>NSCameraUsageDescription</key><string>需要相机权限</string><key>NSPhotoLibraryUsageDescription</key><string>相册权限</string>

3.9 修改项目

  1. 删除Main.storyboard
  2. 删除Info.plist中Main storyboard file base name
  3. 删除项目配置Main Interface

    3.10 修改代理类AppDelegate.m

    ////  AppDelegate.m//  Demo-LBXScan////  Created by witsystem on 2018/3/23.//  Copyright © 2018年 witsystem. All rights reserved.//#import "AppDelegate.h"#import "WITHomeViewController.h"@interface AppDelegate ()@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];WITHomeViewController *vc = [[WITHomeViewController alloc] init];self.window.rootViewController = [[UINavigationController alloc]initWithRootViewController: vc];[self.window makeKeyAndVisible];return YES;}- (void)applicationWillResignActive:(UIApplication *)application {// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.}- (void)applicationDidEnterBackground:(UIApplication *)application {// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.}- (void)applicationWillEnterForeground:(UIApplication *)application {// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.}- (void)applicationDidBecomeActive:(UIApplication *)application {// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.}- (void)applicationWillTerminate:(UIApplication *)application {// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.}@end

3.11 添加文件WITHomeViewController.h

    ////  WITHomeViewController.h//  Demo-LBXScan////  Created by witsystem on 2018/3/23.//  Copyright © 2018年 witsystem. All rights reserved.//#import <UIKit/UIKit.h>@interface WITHomeViewController : UIViewController@end

3.12 添加文件WITHomeViewController.m

    ////  WITHomeViewController.m//  Demo-LBXScan////  Created by witsystem on 2018/3/23.//  Copyright © 2018年 witsystem. All rights reserved.//#import "WITHomeViewController.h"#import <LBXScanViewStyle.h>#import "WITOrderScanViewController.h"@interface WITHomeViewController ()@end@implementation WITHomeViewController- (void)viewDidLoad {[super viewDidLoad];self.title = @"扫一扫";self.view.backgroundColor = [UIColor whiteColor];UIButton *button = [[UIButton alloc] initWithFrame: CGRectMake([UIScreen mainScreen].bounds.size.width * 0.5-50, [UIScreen mainScreen].bounds.size.height * 0.5, 100, 50)];[button addTarget:self action: @selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];[button setTitle: @"扫一扫" forState: UIControlStateNormal];[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];[self.view addSubview: button];}- (IBAction)btnClick:(id)sender {//设置扫码区域参数LBXScanViewStyle *style = [[LBXScanViewStyle alloc]init];style.centerUpOffset = 44;style.photoframeAngleStyle = LBXScanViewPhotoframeAngleStyle_Inner;style.photoframeLineW = 3;style.photoframeAngleW = 18;style.photoframeAngleH = 18;style.isNeedShowRetangle = NO;style.anmiationStyle = LBXScanViewAnimationStyle_LineMove;//qq里面的线条图片UIImage *imgLine = [UIImage imageNamed:@"CodeScan.bundle/qrcode_scan_light_green"];style.animationImage = imgLine;style.notRecoginitonArea = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.6];WITOrderScanViewController *vc = [WITOrderScanViewController new];vc.style = style;vc.isOpenInterestRect = YES;vc.libraryType = SLT_Native;[self.navigationController pushViewController:vc animated:YES];}- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated.}/*#pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {// Get the new view controller using [segue destinationViewController].// Pass the selected object to the new view controller.}*/@end

3.13 添加文件WITOrderScanViewController.h

    ////  WITOrderScanViewController.h//  Restaurant////  Created by witsystem on 2018/3/20.//  Copyright © 2018年 witsystem. All rights reserved.//#import "LBXScanViewController.h"@interface WITOrderScanViewController : LBXScanViewController@end

3.14 添加文件WITOrderScanViewController.m

    ////  WITOrderScanViewController.m//  Restaurant////  Created by witsystem on 2018/3/20.//  Copyright © 2018年 witsystem. All rights reserved.//#import "WITOrderScanViewController.h"#import "LBXAlertAction.h"@interface WITOrderScanViewController ()@end@implementation WITOrderScanViewController- (void)viewDidLoad {[super viewDidLoad];self.cameraInvokeMsg = @"相机启动中";}- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];}#pragma mark -实现类继承该方法,作出对应处理- (void)scanResultWithArray:(NSArray<LBXScanResult*>*)array{if (!array ||  array.count < 1){[self popAlertMsgWithScanResult:nil];return;}//经测试,可以ZXing同时识别2个二维码,不能同时识别二维码和条形码//    for (LBXScanResult *result in array) {////        NSLog(@"scanResult:%@",result.strScanned);//    }LBXScanResult *scanResult = array[0];NSString*strResult = scanResult.strScanned;self.scanImage = scanResult.imgScanned;if (!strResult) {[self popAlertMsgWithScanResult:nil];return;}//TODO: 这里可以根据需要自行添加震动或播放声音提示相关代码//...[self showNextVCWithScanResult:scanResult];}- (void)popAlertMsgWithScanResult:(NSString*)strResult{if (!strResult) {strResult = @"识别失败";}__weak __typeof(self) weakSelf = self;[LBXAlertAction showAlertWithTitle:@"扫码内容" msg:strResult buttonsStatement:@[@"知道了"] chooseBlock:^(NSInteger buttonIdx) {[weakSelf reStartDevice];}];}- (void)showNextVCWithScanResult:(LBXScanResult*)strResult {NSLog(@"二维码为:%@",strResult.strScanned);}@end            

3.15 测试

启动项目扫描二维码,会在控制台打印出二维码,扫描后会调用下面这个方法

    - (void)showNextVCWithScanResult:(LBXScanResult*)strResult {NSLog(@"二维码为:%@",strResult.strScanned);}

项目源码:
https://github.com/ruyulin/Demo-LBXScan.git

IOS开发(17)IOS 使用LBXScan框架开发扫一扫功能相关推荐

  1. 爬虫开发入门:使用 Pyspider 框架开发爬虫

    使用 pyspider 作为爬虫入门框架要比直接用 Scrapy 容易太多,如果你需要快速爬取一个网站,pyspider 爬虫框架是最佳选择之一 pyspider 框架具有以下优点 有 Web 界面用 ...

  2. tfs java开发需要jar_使用Spring框架开发最少需要哪些jar包,依赖jar包有哪些?

    展开全部 最少需要11个jar包,分别是:spring-context.jar commons-logging.jar aspectjrt.jar spring-core.jar aspectjwea ...

  3. iOS-MultipeerConnectivity框架开发(二)

    原文地址:http://www.appcoda.com/intro-ios-multipeer-connectivity-programming/ 编者:在iOS-MultipeerConnectiv ...

  4. 9. Zigbee应用程序框架开发指南 - 属性管理

    1 Zigbee应用程序框架开发指南 - 概述 2 Zigbee应用程序框架开发指南 - 应用程序框架结构 3 Zigbee应用程序框架开发指南 - 应用程序框架目录结构 4 Zigbee应用程序框架 ...

  5. Dart-Aqueduct框架开发(七)

    声明:本文首发于微信订阅号:Dart客栈,微信后台回复05167获取本篇源码 文章为原创,如需转载请注明出处,并告知作者,谢谢! Dart-Aqueduct框架开发目录 Dart-Aqueduct框架 ...

  6. 用PHP开发手机 APP应用API接口开发

    这个帖子写给不太了解PHP与API开发的人 一.先简单回答两个问题: 1.PHP 可以开发客户端? 答:不可以,因为PHP是脚本语言,是负责完成 B/S架构 或 C/S架构 的S部分,即:服务端的开发 ...

  7. iOS开发网络篇—使用ASI框架进行文件下载

    iOS开发网络篇-使用ASI框架进行文件下载 说明:本文介绍iOS网络编程中经常用到的框架ASI,如何使用该框架进行文件的下载. 一.简单介绍 代码示例: 1 #import "YYView ...

  8. iOS - 常用的iOS Mac框架和库以及常用的中文开发博客

    对于iOS以及Mac开发中常用到的一些框架,以及比较好的技术博客做了总结: 主要内容如下: UI 下拉刷新 模糊效果 AutoLayout 富文本 图表 表相关 隐藏与显示 HUD与Toast 对话框 ...

  9. IOS开发基础之使用AFNetworking框架下载服务器资源图片

    IOS开发基础之使用AFNetworking框架下载服务器资源图片 info.plist加入这句 <key>NSAppTransportSecurity</key> <d ...

最新文章

  1. 李开复口中的“联邦学习” 到底是什么?| 技术头条
  2. POJ 2186 Tarjan
  3. 将整个ASCII文件读入C ++ std :: string [重复]
  4. 基于SEAL库实现PSI-报错实录1
  5. AOP面向切面编程在Android中的使用
  6. WatchOS系统开发大全(6)-WKInterfaceLabel
  7. Linux系统中文件^M乱码解决
  8. php判断三角形类型,C#_C#判断三角形的类型,题目描述: 输入三角形的三 - phpStudy...
  9. 如何进行服务器备份操作系统,如何在Linux服务器上做备份和恢复
  10. Java 128陷阱+自动装箱拆箱
  11. linux下tail命令的用法,在Linux命令中tail的用法
  12. docker 阿里云镜像_Springboot工程制作镜像并推送到阿里云
  13. iPhone提示“软件更新失败”下载时出错怎么办?教你解决!
  14. 科学素养题(2022年2月-2022年10月)
  15. SnowNLP包情感分析
  16. Gartner 魔力象限:安全信息和事件管理 2020
  17. Kubernetes Scheduler源码分析--启动过程与多队列缓存(续)
  18. java词云生成,kumo项目详解
  19. java计算工龄,java计算工龄
  20. UVA 537 解题报告

热门文章

  1. GitHub 上标星 115k+ 的 Java 教程
  2. OSPF中的SPF计算
  3. 一个80年小子的创业道理,和所有准备创业或者正在创业的兄弟们共享
  4. 遗传算法之旅行家问题(TSP)
  5. linux FTP云盘
  6. vue-cli3以后,关于webpack打包等的相关配置
  7. 考研必备100个网站
  8. unity重定向_Unity 骨骼动画的运行时重定向
  9. 研究生复试--中文自我介绍
  10. PDF如何转换成Word