1羞延、替換gem源
- 雖然Mac自帶Ruby但是安裝
cocoapods
需要gem
,gem
是一個管理Ruby庫和程序的標(biāo)準(zhǔn)包,它通過RubyGem源來查找、安裝茄猫、升級和卸載軟件包狈蚤。因為gem默認(rèn)的服務(wù)器被墻,因此在安裝之前需要將gem服務(wù)器替換成國內(nèi)的地址划纽。
$ gem sources --remove https://rubygems.org/ //移除
$ gem sources --add https://ruby.taobao.org/ //替換
- 檢查替換結(jié)果
$ gem sources -l
(最后建議升級一下gem:$ sudo gem update --system
)
2脆侮、安裝cocoapods
- gem源替換好之后就可以安裝cocoapods了
$sudo gem install -n /usr/local/bin cocoapods $ pod setup
- 不出意外的話setup這一步會很慢或者無限卡
Setting up CocoaPods master repo
,這是因為要在github下載代碼勇劣,我這一步一直有問題靖避,查詢網(wǎng)上都說要將specs倉庫鏡像換成gitcafe上的鏡像或者是 oschina 上的鏡像即:
$ pod repo remove master $ pod repo add master https://git.coding.net/CocoaPods/Specs.git //或者 $ pod repo add master https://git.oschina.net/akuandev/Specs.git
- 但是執(zhí)行
$ pod repo remove master
之后老是提示[!] repo master does not exist
雖后執(zhí)行$ pod repo add master https://git.coding.net/CocoaPods/Specs.git
之后又會提示[!] To setup the master specs repo, please runpod setup
. 然后就無限卡死這兩步,不知道是因為cocoapods版本的問題還是網(wǎng)絡(luò)的問題比默,最后直接手動將代碼git到本地得以解決問題:
$ git clone https://git.coding.net/CocoaPods/Specs.git ~/.cocoapods/repos/master
- git完成之后如下:
- 然后執(zhí)行
$ pod repo update $ pod repo
- 結(jié)果如下:
- 至此cocoapods安裝完畢
3幻捏、cocoapods的使用
- 首先cd命令到項目根目錄下,生成Podefile文件
$pod init //會生成模板的Podfile文件
- 指定依賴命咐,例如
target 'B01-opencvTest' do pod 'SVProgressHUD' end
- 保存文件后執(zhí)行
$pod install --verbose --no-repo-update
- 提示
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.
,打開工作空間.xcworkspace文件就可以開始愉快的編程了粘咖。