将第 3 方库 ZXing 导入 Xcode [英] Importing 3rd party library ZXing into Xcode

查看:34
本文介绍了将第 3 方库 ZXing 导入 Xcode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了多种方法将第 3 方库ZXing"导入到我的 iOS 应用程序中,但所有方法都很痛苦或根本不起作用.如果有人可以建议我做错了什么,或者有更好的方法来导入 ZXing 等库,我将不胜感激.

I've tried a number of ways to import the 3rd party library 'ZXing' into my iOS app, but all have been painful or have simply not worked. If anyone could suggest either what I'm doing wrong, or a better way to import a library such as ZXing, I'd be very grateful.

一定比这更容易!!!

这就是我所做的,结果:

This is what I've done, with results :

MyGreatApp 的目录结构(撰写本文时)

Directory structure of MyGreatApp (at time of writing)

/MyGreatApp/MyGreatApp.xcworkspace (main workspace that compiles the
   application)
 /MyGreatApp/Projects/MyGreatApp/MyGreatApp.xcodeproj   
 /MyGreatApp/Projects/MyGreatApp/(All source code for MyGreatApp)   
 /MyGreatApp/Projects/other-inhouse-project/other-inhouse-project/other-inhouse-project.xcodeproj
 /MyGreatApp/Projects/other-inhouse-project/other-inhouse-project/(Source
   code for other-inhouse-project)   
 /MyGreatApp/Projects/other-inhouse-project/RestKit/RestKit.xcodeproj 
 /MyGreatApp/Projects/other-inhouse-project/RestKit/(source code for  
   restKit)

将 ZXing 项目添加到工作区:

从 git hub 下载项目:https://github.com/TheLevelUp/ZXingObjC(最新版本))

Download project from git hub : https://github.com/TheLevelUp/ZXingObjC (latest release)

将项目复制到/Projects(在 svn repo 中).

Copy project to /Projects (in svn repo).

打开 MyGreatApp 工作区,添加文件"-> 选择ZXingObjC.xcodeproj".

Open MyGreatApp workspace, 'add Files' -> select 'ZXingObjC.xcodeproj'.

将编译后的库 (libZXingObjC-iOS.a) 添加到 MyGreatApp 构建阶段,从 ZXing 产品拖放.添加ZXing需要的框架.

Add the compiled library (libZXingObjC-iOS.a) to the MyGreatApp build phases drag and drop from ZXing products. Add the frameworks required by ZXing.

在头搜索路径和库搜索路径中添加 ZXing 的路径.$(PROJECT_DIR)/../../Projects/ZXingObjC-2.2.6/ZXingObjC".使用 $(PROJECT_DIR) 这样路径是相对的并且适用于所有构建机器.

Add Path to ZXing in header search paths and library search paths. "$(PROJECT_DIR)/../../Projects/ZXingObjC-2.2.6/ZXingObjC" . Use $(PROJECT_DIR) so the path is relative and works on all build machines.

将 ZXing 构建设置更改为不使用 arm64 架构,因为由于旧的 restKit 库,我们目前不支持它.

Changed ZXing build settings to NOT use arm64 architecture, as we currently don't support it due to the old restKit library.

为了构建其他配置,我找到的唯一解决方案是在 ZXing 项目中添加一个名称完全相同的配置,即添加 QA (PAT12)、QA (PAT14) 等(这是不理想)

In order for other configurations to build, the only solution I've found is to add a configuration to the ZXing project with exactly the same name, i.e. adding QA (PAT12), QA (PAT14) etc etc. (this is not ideal)

结果:

项目编译并运行良好,但上述步骤相当耗时.

Project compiles and works fine, the above steps were quite time consuming however.

编译 ZXing 不会产生错误警告.

Compiling ZXing produces no error warnings.

可以使用

将ZXing文件添加到MyGreatApp项目(与项目一起编译的文件):

从 git hub 下载项目:https://github.com/TheLevelUp/ZXingObjC(最新版本))

Download project from git hub : https://github.com/TheLevelUp/ZXingObjC (latest release)

将 ZXingObjC 文件夹拖到 Xcode 上.确保在点击添加"之前选中复制项目".

Drag the ZXingObjC folder onto Xcode. Make sure "Copy items" is checked before clicking "Add".

添加ZXing需要的框架.

Add the frameworks required by ZXing.

不得不改变 ZXing 源代码行以允许它编译(不知道这可能是什么结果,这里有一些信息:https://github.com/TheLevelUp/ZXingObjC/issues/118)

Had to alter line of ZXing source code to allow it to compile (not sure what the result of this might be, some info here : https://github.com/TheLevelUp/ZXingObjC/issues/118)

@property (nonatomic, strong) /*__attribute__((NSObject))*/ dispatch_queue_t captureQueue;

结果:

项目编译并似乎"运行良好(但是担心破解 ZXing 源代码)

Project compiles and 'seems' to run fine (nervous about hacking the ZXing source code however)

编译会产生大约 180 个错误警告.

Compiling produces about 180 error warnings.

无法使用

使用 CocoaPods 添加 ZXing 项目:

按照 CocoaPods 网站上的说明进行安装.

Followed instructions on CocoaPods website for installation.

尝试在与 MyGreatApp.xcproject 相同的目录中创建 Podfile,但这导致编译器错误,并且pod install"命令在与我的项目相同的文件夹中创建了一个新的 xcworkspace 文件(我们已经在其他地方创建了一个)

Tried creating Podfile in the same Directory as MyGreatApp.xcproject, but this resulted in compiler errors, and the 'pod install' command created a new xcworkspace file in the same folder as my project (we already have one somewhere else)

尝试在与 MyGreatApp.xcworkspace 相同的目录中创建 Podfile,但这导致 pod install 命令不起作用

Tried creating a Podfile in the same directory as MyGreatApp.xcworkspace, but this resulted in the pod install command not working

结果:

无法使用 CocoaPods 安装.

Cannot install using CocoaPods.

无法使用

任何关于将 ZXing 添加到我的项目的好方法的帮助或建议都会非常有帮助.

Any help or suggestions as to how a good way might be to add ZXing to my project would be very helpful.

推荐答案

如果您想将第三方 API 添加到您的项目中,只需按照以下步骤操作:

If you want to add third party API to your project then simply follow these steps:

  • 首先将第三方库复制到您的项目中.
  • 然后转到目标 -> 构建阶段 -> 将二进制文件与库链接.
  • 点击 + 符号.
  • 添加其他 &从您放置它的项目中选择.

这是将任何第三方 API 添加到项目的最佳方法.

This is the best approach to add any third party API to a project.

希望对大家有所帮助.

这篇关于将第 3 方库 ZXing 导入 Xcode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆