1、检查或更新gem版本,使用淘宝提供的国内镜像源
a、添加淘宝镜像源
gem sources --remove https://rubygems.org
gem source -a https://ruby.taobao.org
b、更新gem
sudo gem update --system
等待更新完成
2、安装cocoapods
sudo gem install cocoapods
等待安装完成
3、更换cocoapods镜像源,提高访问速度
pod repo remove master
pod repo add master http://git.oschina.net/akuandev/Specs.git
pod repo update
4、安装
pod setup
等待安装完成
5、测试
使用xcode新建一个项目,在终端中定位到项目根目录。输入命令pod init
,等待命令执行完成。执行完成后会在根目录下生成一个Podfile文件,使用vim编辑此文件,输入命令vim Podfile
,文件内容如下:
# Uncomment this line to define a global platform for your project
platform :ios, '7.0'
# Uncomment this line if you're using Swift
# use_frameworks!
target '项目名称' do
end
按i
键开始编辑,在end
之前输入要使用的第三库,例如SDWebImage,完整代码如下:
# Uncomment this line to define a global platform for your project
platform :ios, '7.0'
# Uncomment this line if you're using Swift
# use_frameworks!
target '项目名称' do
pod 'SDWebImage', '~> 3.7.3'
end
按ESC
键,在输入wq
键保存刚才输入的内容。接着,在终端中输入pod install
,开始安装,等待安装完成。看到Pod installation complete!信息,表示完整完成。以后每次打开项目,直接打开文件"项目名称.xcworkspace"。
6、常用命令
初始化项目
pod init
安装
pod install
更新
pod update
执行安装或更新默认会更新本地仓库,如果不想更新,加入参数--no-repo-update
,例如:
pod update --no-repo-update
搜索第三库
pod search 第三方库名称