首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

CocoaPods 装配使用

2013-04-02 
CocoaPods 安装使用CocoaPods是一个负责管理iOS项目中第三方开源代码的工具。CocoaPods项目的源码在Github

CocoaPods 安装使用

CocoaPods是一个负责管理iOS项目中第三方开源代码的工具。CocoaPods项目的源码在Github上管理。该项目开始于2011年8月12日,经过一年多的发展,现在已经超过1000次提交,并且持续保持活跃更新。开发iOS项目不可避免地要使用第三方开源库,CocoaPods的出现使得我们可以节省设置和更新第三方开源库的时间。

安装

安装方式异常简单, Mac下都自带ruby,使用ruby的gem命令即可下载安装:

$ gem install cocoapods$ pod setup


使用:
Open Terminal, and navigate to the folder where your project is. Type the following:
touch Podfileopen -e Podfile


TextEdit should open up showing an empty file. You just created the pod file and opened it! Ready to add some content to the empty pod file?
Copy and paste the following lines into the TextEdit window:
platform :iospod 'AFNetworking', '0.9.1'

Now, save the file and close TextEdit, going back to terminal. Ready to configure your project?
Issue the following command via Terminal:
pod install



You should see output similar to the following:
Updating spec repo `master'Installing AFNetworking (0.9.1)Generating support files


It might also tell you something like this:
[!] From now on use `CocoaPodsExample.xcworkspace'


If you type ls now (or browse the project folder using Finder), you’ll see that CocoaPods created a Pods folder – where it stores all dependencies – and CocoaPodsExample.xcworkspace.

VERY IMPORTANT!From now on, as the command-line warning mentioned, you must always open the workspace (CocoaPodsExample.xcworkspace) and not the project!


现在,你的所有第三方库都已经下载完成并且设置好了编译参数和依赖,你只需要记住如下2点即可:

使用CocoaPods生成的 .xcworkspace 文件来打开工程,而不是以前的 .xcodeproj 文件。
每次更改了Podfile文件,你需要重新执行一次pod install命令

热点排行