一、概要
iOS開發(fā)時泳唠,項(xiàng)目中會引用許多第三方庫,CocoaPods 可以用來方便的統(tǒng)一管理這些第三方庫宙搬。
二笨腥、安裝
要使用CocoaPods,那就要下載安裝它勇垛,而下載安裝CocoaPods需要Ruby環(huán)境
- 1脖母、Ruby環(huán)境搭建
- a 查看下當(dāng)前ruby版本:打開終端輸入 ruby -v
- b 更新ruby
終端輸入如下命令(把Ruby鏡像指向ruby-china,避免被墻闲孤,你懂得),執(zhí)行命令
gem sources --remove https://rubygems.org/
gem sources -a https://gems.ruby-china.com/
gem sources -l (用來檢查使用替換鏡像位置成功)
- 2谆级、下載安裝CocoaPods
終端輸入:
sudo gem install -n /usr/local/bin cocoapods
出現(xiàn) 1 gem installed
說明已經(jīng)安裝成功
- 3、使用CocoaPods
- 新建一個項(xiàng)目,名字XXXXX
- 終端中哨苛,cd到項(xiàng)目總目錄
- 執(zhí)行命令
pod init
- 執(zhí)行
pod install --no-repo-update
- 打開工程目錄下的Podfile文件添加要依賴的第三方庫 如:
Alamofire
寫入pod 'Alamofire'
保存文件
Podfile文件
* 再次執(zhí)行 `pod install --no-repo-update` 即可
現(xiàn)在打開項(xiàng)目點(diǎn)擊 XXXXX.xcworkspace
鸽凶,cocoapod安裝完成
- 4.更新
如果需要添加新的第三方庫,只需要在Podfile文件下添加即可建峭,然后執(zhí)行pod install --no-repo-update
三玻侥、安裝過程遇到的報錯以及解決方式(持續(xù)更新...)
1.報SSL錯誤
ERROR: SSL verification error at depth 2: unable to get local issuer certificate (20)
ERROR: You must add /C=US/O=VeriSign, Inc./OU=Class 3 Public Primary Certification Authority to your local trusted store
ERROR: SSL verification error at depth 1: unable to get local issuer certificate (20)
ERROR: You must add /C=IL/O=StartCom Ltd./OU=Secure Digital Certificate Signing/CN=StartCom Certification Authority to your local trusted store
ERROR: SSL verification error at depth 2: self signed certificate in certificate chain (19)
ERROR: Root certificate is not trusted (/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA)
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/pod
解決方式:
sudo gem install -n /usr/local/bin cocoapods