ios 如何将 AFNetworking 添加到 XCode 应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21291478/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add AFNetworking to XCode app
提问by James Dunn
I'm relatively new to XCode and iOS.My background for understanding how to add libraries/dependencies to a project is in the world of Java and Maven.
我对 XCode 和 iOS 比较陌生。我了解如何向项目添加库/依赖项的背景是 Java 和 Maven。
I need to add AFNetworkingto my project and have been unable to do so successfully.
我需要将 AFNetworking 添加到我的项目中,但一直无法成功。
First, I tried going to my project -> Build Phases -> Link Binary
With Libraries, clicking the "+" button, and then search for AFNetworking
from the list. It wasn't in the list.
首先,我尝试转到my project -> Build Phases -> Link Binary
With Libraries,单击“+”按钮,然后AFNetworking
从列表中搜索。 它不在列表中。
So, I figured I'd have to add it using the "Add Other..." option. Which means, of course, I'd need to download AFNetworking
somehow. I'm not sure I was able to download it in the correct form -- it seems all I could get was the AFNetworking
project itself, rather than a framework (if I understand correctly, frameworks are analogous to jars? Can you generate a framework by building an iOS project in a certain way?). I downloaded it from their GitHub page. (I also tried their "Getting Started" guide, but it had me using CocoaPods
, which I couldn't get to work right and I'd rather avoid it for now.)
所以,我想我必须使用“添加其他...”选项添加它。当然,这意味着我需要以AFNetworking
某种方式下载。我不确定我是否能够以正确的形式下载它——似乎我能得到的只是AFNetworking
项目本身,而不是框架(如果我理解正确,框架类似于 jar?你能生成一个框架吗?以某种方式构建 iOS 项目?)。我是从他们的GitHub 页面下载的。(我也尝试过他们的“入门”指南,但它让我使用了CocoaPods
,我无法正常工作,我现在宁愿避免使用它。)
I've tried adding project files and folders from AFNetworking
just to see if they worked (but of course they don't -- I think I need some sort of .framework
file).
我已经尝试添加项目文件和文件夹,AFNetworking
只是为了查看它们是否有效(但当然它们没有 - 我想我需要某种.framework
文件)。
Bottom line: I can't seem to find a way to add AFNetworking
to my project. How can I do it?
底线:我似乎找不到添加AFNetworking
到我的项目的方法。我该怎么做?
回答by Michael Dautermann
It sounds like you got the first part down, which is downloading it from the GitHub page.
听起来您已经完成了第一部分,即从 GitHub 页面下载它。
When I follow this tutorial, it shows how they imported AFNetworking into their own sample project (that is, you'll see a "AFNetworking" group in the list of files and folders along the left side of your Xcode window).
当我按照本教程进行操作时,它显示了他们如何将 AFNetworking 导入到他们自己的示例项目中(也就是说,您将在 Xcode 窗口左侧的文件和文件夹列表中看到一个“AFNetworking”组)。
Once AFNetworking is building along with the rest of your code in your project, you should be able to call into the various AFNetworking API's from your code. You'll need to make certain to add in the appropriate "#import "AFNetworking.h"
" lines into your source code files from which you'll be calling AFNetworking.
一旦 AFNetworking 与项目中的其余代码一起构建,您应该能够从您的代码调用各种 AFNetworking API。您需要确保将适当的“ #import "AFNetworking.h"
”行添加到您将调用 AFNetworking 的源代码文件中。
回答by edzio27
Use pods, than you wont have to upload AFNetworking to your github project, and there is no worry about wrong linkers etc.
使用 pods,您不必将 AFNetworking 上传到您的 github 项目,并且不用担心错误的链接器等。
Use pods: install pods
使用 pods:安装 pods
Instalation AFNetworkign with pods: install AFNetworking
回答by Maroon5Five
I believe if you download their code you can generate the .a file using the process in this stack overflow answer: (obviously replacing the project they are getting from gihut with the project you found) How to create framework from Xcode 4 project?
我相信如果您下载他们的代码,您可以使用此堆栈溢出答案中的过程生成 .a 文件:(显然,将他们从 gihut 获得的项目替换为您找到的项目) 如何从 Xcode 4 项目创建框架?