前言
CocoaPods是一个负责管理iOS项目中第三方开源代码的工具。
二、安装
由于网上的教程基本都大同小异,但细节之处还不是很完善,所以借机会在这里补充下:
注:要使用CocoaPods,那就要下载安装它,而下载安装CocoaPods需要Ruby环境
1.Ruby环境搭建
当前安装环境为Mac Pro 10.11.1。Mac OS本身自带Ruby,但还是更新一下保险,因为升级了系统之后,可能会出现一些意想不到的情况,最好还是更新一下Ruby。
- 查看下当前ruby版本:打开终端输入 ruby -v(确实安装了,不过iOS9使用https协议替换http协议,所以以前挂靠在淘宝下ruby的源的路径也要修改下,顺便更新下ruby)
CYdediannao:~ lcy$ ruby -v ruby 2.0.0p645 (2015-04-13 revision 50299) [universal.x86_64-darwin15]
- 淘宝已经停止基于 HTTP 协议的镜像服务, 请在配置中使用 HTTPS 协议代替
CYdediannao:~ lcy$ gem sources - l
*** CURRENT SOURCES ***
http://ruby.taobao.org/
CYdediannao:~ lcy$ gem sources --add https://ruby.taobao.org/ --remove http://ruby.taobao.org/
https://ruby.taobao.org/ added to sources
http://ruby.taobao.org/ removed from sources
- gem sources -l (用来检查使用替换镜像位置成功,然后升级ruby
或者是CYdediannao:~ lcy$ sudo gem install rails
CYdediannao:~ lcy$ sudo gem update --system
2.下载安装CocoaPods
CYdediannao:~ lcy$ sudo gem install cocoapods
出现的错误###:原因是该文件夹没有修改的权限
CYdediannao:~ lcy$ sudo gem install cocoapods
Fetching: nap-1.0.0.gem (100%)
Successfully installed nap-1.0.0
Fetching: molinillo-0.4.0.gem (100%)
Successfully installed molinillo-0.4.0
Fetching: cocoapods-trunk-0.6.4.gem (100%)
Successfully installed cocoapods-trunk-0.6.4
Fetching: cocoapods-try-0.5.1.gem (100%)
Successfully installed cocoapods-try-0.5.1
Fetching: cocoapods-stats-0.6.2.gem (100%)
Successfully installed cocoapods-stats-0.6.2
Fetching: cocoapods-search-0.1.0.gem (100%)
Successfully installed cocoapods-search-0.1.0
Fetching: cocoapods-downloader-0.9.3.gem (100%)
Successfully installed cocoapods-downloader-0.9.3
Fetching: xcodeproj-0.28.2.gem (100%)
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/xcodeproj
10.11以上系统使用命令: sudo gem install -n /usr/local/bin cocoapods
CYdediannao:~ lcy$ sudo gem install -n /usr/local/bin cocoapods
Password:
Successfully installed xcodeproj-0.28.2
Fetching: cocoapods-core-0.39.0.gem (100%)
Successfully installed cocoapods-core-0.39.0
Fetching: cocoapods-0.39.0.gem (100%)
Successfully installed cocoapods-0.39.0
Parsing documentation for xcodeproj-0.28.2
Installing ri documentation for xcodeproj-0.28.2
Parsing documentation for cocoapods-core-0.39.0
Installing ri documentation for cocoapods-core-0.39.0
Parsing documentation for cocoapods-0.39.0
Installing ri documentation for cocoapods-0.39.0
3 gems installed
3.使用命令 pod search AFNetworking 查找某一个库,看cocoapods有没有安装好,搜索结果如下,已经安装好了cocoa pods
-> AFNetworking (2.6.0)
A delightful iOS and OS X networking framework.
pod 'AFNetworking', '~> 2.6.0'
- Homepage: https://github.com/AFNetworking/AFNetworking
- Source: https://github.com/AFNetworking/AFNetworking.git
- Versions: 2.6.0, 2.5.4, 2.5.3, 2.5.2, 2.5.1, 2.5.0, 2.4.1, 2.4.0, 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] - 2.6.0, 2.5.4, 2.5.3, 2.5.2, 2.5.1,
2.5.0, 2.4.1, 2.4.0, 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-1 repo]
- Subspecs:
- AFNetworking/Serialization (2.6.0)
- AFNetworking/Security (2.6.0)
- AFNetworking/Reachability (2.6.0)
- AFNetworking/NSURLConnection (2.6.0)
- AFNetworking/NSURLSession (2.6.0)
- AFNetworking/UIKit (2.6.0)
-> 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] - 0.0.5, 0.0.4,
0.0.3, 0.0.2, 0.0.1 [master-1 repo]
-> AFNetworking+Ext (1.2.1)
AFNetworking的封装, 并提供一个 UIImageView+DYLoading cache in fileSystem+memory
pod 'AFNetworking+Ext', '~> 1.2.1'
- Homepage: https://github.com/junhaiyang/AFNetworkingExt
- Source: https://github.com/junhaiyang/AFNetworkingExt.git
- Versions: 1.2.1, 1.2, 1.1, 1.0, 0.5, 0.4, 0.3 [master repo] - 1.2.1, 1.2,
1.1, 1.0, 0.5, 0.4, 0.3 [master-1 repo]
- Subspecs:
- AFNetworking+Ext/Base (1.2.1)
- AFNetworking+Ext/AFCustomRequestOperation (1.2.1)
- AFNetworking+Ext/AFDownloadRequestOperation (1.2.1)
- AFNetworking+Ext/AFTextResponseSerializer (1.2.1)
- AFNetworking+Ext/example (1.2