下載安裝
- 1 終端操作
sudo gem install cocoapods - 2 查詢源
gem sources -l - 3 如果不是淘寶的,則應該更正
刪除之前的源:gem sources --remove https://rubygems.org/
增加淘寶的源:gem sources -a https://ruby.taobao.org/ - 4 再次查看源 確保已經更換源成功
gem sources -l - 5 設置pods
pod setup --verbose - 6 查看pods版本,如果有版本號出現,說明安裝成功
pod --version
使用
- 1 終端 找到工程目錄
cd Desktop/Test - 2 初始化
pod init 如果pod成功安裝,會產生一個Podfile文件 - 3 下載第三方庫(例子:MBProgressHUD)
搜索: pod search hud(這里輸入關鍵字即可) - 4 使用Xcode打開Podfile
下載: open -a Xcode Podfile ->把需要的版本號(pod 'MBProgressHUD', '~> 0.9.2') -> pod install - 5 下次安裝
把需要的第三方庫粘貼 -> pod update
注意
- 1 利用CocoPods管理類庫后, 以后打開項目就用xxxx.xcworkspace 打開,而不是 之前的.xcodeproj文件
- 2 每次更改了Podfile文件,你需要重新執行一次pod update命令。
- 3 CocoaPods在執行pod install和pod update時,會默認先更新一次CocoPods的 spec倉庫索引。使用--no-repo-update參數可以禁止其做索引更新操作
pod install --no-repo-update
pod update --no-repo-update
Xcode寫入Podfile路徑錯誤解決方法
錯誤提示:
xcrun: error: active developer path ("/Applications/Xcode 2.app/Contents/Developer") does not exist, use xcode-select --switch path/to/Xcode.app
to specify the Xcode that you wish to use for command line developer tools (or see man xcode-select
)
解決方法:
終端輸入:sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/