一、安裝CocoaPods
1.首先更新gem到最新版本,在終端中輸入:sudo gem update --system
2.刪除自帶的ruby鏡像,終端輸入:gem sources --remove https://rubygems.org/。
3.添加淘寶的鏡像,終端輸入:gem sources -a https://gems.ruby-china.org/(原來的淘寶鏡像 https://ruby.taobao.org/已經不能用了)。
4.可以用gem sources -l 來檢查使用替換鏡像位置成功,結果應該只有 https://gems.ruby-china.org/ 才對。
安裝過程中可能出現證書錯誤的問題
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)
解決方法可以參考文章cocopads /O=Digital Signature Trust
按照文章中的操作,需要更新ruby環境
1)首先要安裝Homebrew終端輸入這條命令即可/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2)安裝rvm$ curl -L get.rvm.io | bash -s stable
3)裝載rvm$ source ~/.rvm/scripts/rvm
4)安裝2.3.0版本ruby$ rvm install 2.3.0
5)將2.3.0設為默認$ rvm use 2.3.0 --default
使用第3條命令,有可能找不到目錄,在安裝ruby的時候,會有一條提示安裝到了哪個目錄,
5、安裝CocoaPods,終端輸入:sudo gem install cocoapods。
6、然后配置下CocoaPods,終端輸入:pod setup。
CocoaPods使用
1、查找第三方庫,比如查找SwiftyJSON,pod search SwiftyJSON
2、xcode集成cocoapods之后,可以使用命令
pod install 添加第三方庫
pod update 更新第三方庫的版本
3、如果遇到pod install或者pod update慢的問題,原因在于當執行以上兩個命令的時候會升級CocoaPods的spec倉庫,加一個參數可以省略這一步,然后速度就會提升不少。加參數的命令如下:
pod install --verbose --no-repo-update
pod update --verbose --no-repo-update
更多內容,請參考文章