1.升级Ruby环境
sudo gem update –system
2.安装CocoaPods时我们要访问cocoapods.org,用淘宝的RubyGems镜像来代替官方版本,执行以下命令:
gem sources --remove https://rubygems.org/
//等有反应之后再敲入以下命令
gem sources -ahttps://ruby.taobao.org/
3.为了验证你的Ruby镜像是并且仅是taobao,可以用以下命令查看:
gem sources –l
只有在终端中出现下面文字才表明你上面的命令是成功的:
<span style="font-family:SimSun;font-size:14px;">*** CURRENT SOURCES ***</span>
<span style="font-family:SimSun;font-size:14px;"> </span>
<span style="font-family:SimSun;font-size:14px;">http://ruby.taobao.org/</span>
4.安装Cocoapods,在终端输入命令
sudo gem install cocoa pods
#设置
pod setup //这步需要较长时间,可以用命令du -sh *查看进度
5.在项目中创建cocoapod
vim Podfile
Podfile的内容:
# 最低支持的 iOS 版本
platform :ios, '8.0'
# Swift 项目需要将框架转换为 frameworks 才能使用
use_frameworks!
#添加第三方库的target
target “test” do
# 框架列表
pod 'AFNetworking’, ‘3.1.0’
#记得要加上end
end
之后就可以利用CocoPods下载AFNetworking类库了。还是在终端中的当前项目目录下,运行以下命令:
#安装
pod install
6.pod命令汇总
7.安装中遇到的问题
# 第一次使用安装框架
$ pod install
# 今后升级、添加、删除框架,或者框架不好用
$ pod update
# 搜索框架
$ pod search XXX
# 在项目文件夹下创建默认的 Podfile
$ pod init
安装cocoa pods时,在终端执行pod search第三方框架时出错:[!] Unable to find a pod with name, author, summary, ordescriptionmatching `AFNetworking`
解决方案:执行rm ~/Library/Caches/CocoaPods/search_index.json
然后再执行pod search第三方框架
执行pod install时报错:[!] The dependency `AFNetworking` is not used in any concrete target.
Pod file文件内容:#最低支持的 iOS 版本
platform :ios, '8.0'
# Swift项目需要将框架转换为 frameworks才能使用
use_frameworks!
#框架列表
pod 'AFNetworking’, ‘3.1.0’
解决方案:在Podfile文件内容中加上:target "RWTFlickrSearch" do,记得在最后要加上end
修改后的Podfile:#最低支持的 iOS 版本
platform :ios, '8.0'
# Swift项目需要将框架转换为 frameworks才能使用
use_frameworks!
#添加第三方库的target
target “test” do // test是项目的target
#框架列表
pod 'AFNetworking’, ‘3.1.0’
#记得要加上end
end