CocoaPods安装和使用教程

安装过程:

xcode -> homebrew -> RVM -> Ruby -> CocoaPats

1 安装xcode 

2 homebrew 官方网站:http://brew.sh/index_zh-cn.html

3 Ruby 

$ gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/
$ gem sources -l
*** CURRENT SOURCES ***

https://ruby.taobao.org

4 安装cocoapods

1)$ sudo gem install cocoapods

//sudo 为获取管理员权限所以需要输入密码

2)$ sudo gem update --system

//如果提示gem版本过低需要升级gem

3)$ pod search afnetworking 

//afnetworking 为第三方库的名称

//如果cocoapods支持

将会出现  :  /*

-> AFNetworking (2.3.1)

A delightful iOS and OS X networking framework.

pod 'AFNetworking', '~> 2.3.1’(这个语句是需要在编辑Podfile的时候输入的命令,即是如何安装下载相关类库的指令)

- Homepage: https://github.com/AFNetworking/AFNetworking

- Source: https://github.com/AFNetworking/AFNetworking.git

- Versions: 2.3.1, 2.3.0, 2.2.4, 2.2.3, 2.2.2, 2.2.1, 2.2.0, 2.1.0,

2.0.3, 2.0.2, 2.0.1, 2.0.0, 2.0.0-RC3, 2.0.0-RC2, 2.0.0-RC1, 1.3.4, 1.3.3,

1.3.2, 1.3.1, 1.3.0, 1.2.1, 1.2.0, 1.1.0, 1.0.1, 1.0, 1.0RC3, 1.0RC2, 1.0RC1,

0.10.1, 0.10.0, 0.9.2, 0.9.1, 0.9.0, 0.7.0, 0.5.1 [master repo]

- Sub specs: - AFNetworking/Serialization (2.3.1) -

AFNetworking/Security (2.3.1) - AFNetworking/Reachability (2.3.1) -

AFNetworking/NSURLConnection (2.3.1) - AFNetworking/NSURLSession (2.3.1)

- AFNetworking/UIKit (2.3.1)

-> AFNetworking+AutoRetry (0.0.5)

Auto Retries for AFNetworking requests

pod 'AFNetworking+AutoRetry', '~> 0.0.5'

- Homepage: https://github.com/shaioz/AFNetworking-AutoRetry

- Source: https://github.com/shaioz/AFNetworking-AutoRetry.git

- Versions: 0.0.5, 0.0.4, 0.0.3, 0.0.2, 0.0.1 [master repo]

*/

/*

如果没有成功,提示:Setting up CocoaPods master repo
cocoapods 安装有两个步骤:A.cocoapods环境安装 B.cocoapods主枝创建(相当于从cocoapods服务器上checkout一份到你的电脑)
7.移除cocoapods主支
pod repo remove master

8.修改cocoapods地址
pod repo add master https://gitcafe.com/akuandev/Specs.git
//其中https://gitcafe.com/akuandev/Specs.git 
也可还成http://git.oschina.net/akuandev/Specs.git

9.更新cocoapods主支
pod repo update

*/

10 $ cd (工程文件目录)

11 $ vim Podfile

12 在podfile中写入你想要的第三方库

eg:pod 'JSONKit','~>1.5pre'  

//库的名称  库的版本

13 退出编辑 并 保存:「esc」「:」 「wq」

14 安装第三方库 : $ pod install

15 退出所有工程文件 并 在工程中使用第三方库 :$ from now on use '(工程名称)'

原文地址:https://www.cnblogs.com/conanwin/p/4877414.html