前言:新電腦,安裝CocoaPods,以及簡單使用測試。
1.安裝brew:
brew 又叫Homebrew,是Mac OSX上的軟件包管理工具,能在Mac中方便的安裝軟件或者卸載軟件, 只需要一個命令, 非常方便,
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”```
官網(wǎng) http://brew.sh/
更新brew:
`brew update`
#2.使用brew安裝ruby
brew install ruby
#3.安裝CocoaPods
首先替換一下ruby源
gem sources -r https://rubygems.org/
gem sources -a https://ruby.taobao.org/
gem sources -l
只有在終端中出現(xiàn)下面文字才表明你上面的命令是成功的:
https://ruby.taobao.org/
這時候,再次在終端中運行:
sudo gem install cocoapods
然后:
pod setup
此時,安裝pod常??ㄔ赻Setting up CocoaPods master repo`,這句,
在終端依次運行:
pod repo remove master
pod repo add master http://git.oschina.net/akuandev/Specs.git
git clone https://git.coding.net/CocoaPods/Specs.git ~/.cocoapods/repos/master
等待......等待......等待......
此時可能會報錯:
remote: Compressing objects: 100% (391887/391887), done.
error: RPC failed; curl 56 SSLRead() return error
運行下面命令:
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
如果未能解決,請參照下面內(nèi)容:
http://blog.csdn.net/wm9028/article/details/51840759
然后,重復(fù)上面的命令`pod repo remove master`……
等待......等待......等待......
ps:在此期間控制臺會出現(xiàn)進(jìn)度,或者另開一個控制臺運行下面代碼
`cd ~/.cocoapods/`
然后執(zhí)行查看.cocoapods文件的大小命令:
`du -sh *`
或
`while true; do du -sh ~/.cocoapods/; sleep 10; done`
(最終大小為853M,2016-10-22)
直到出現(xiàn)以下信息,OK!安裝完成!
remote: Counting objects: 872155, done.
remote: Compressing objects: 100% (391887/391887), done.
remote: Total 872155 (delta 396641), reused 872155 (delta 396641)
Receiving objects: 100% (872155/872155), 347.43 MiB | 654.00 KiB/s, done.
Resolving deltas: 100% (396641/396641), done.
Checking connectivity... done.
Checking out files: 100% (115143/115143), done.
測試CocoaPods是否安裝成功:
pod search alamofire
如果能夠查找到alamofire,則表示安裝成功?。。?
#4.CocoaPods的使用
首先,cd到工程的目錄中
cd xxx
然后,創(chuàng)建podfile文件
vim podfile
然后,輸入以下內(nèi)容:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!
target 'PodTest' do
pod 'Alamofire', '~> 4.0'
pod 'SDWebImage', '~> 4.0.0-beta2'
end
(PodTest為工程名稱,
use_frameworks! 選項是告訴 CocoaPods 使用 framework 而不是靜態(tài)庫。這在 Swift 項目中是必選。
platform 的意思是系統(tǒng)支持的最低版本
target是工程名
do開始 end結(jié)束)
然后,按esc退出編輯,
然后,輸入`:wq`,關(guān)閉并保存podfile文件
最后,輸入
pod install
等待......等待......等待......
OK!
打開工程目錄發(fā)現(xiàn)多了一個Pods目錄,里面有剛才install的三方庫,
雙擊`. xcworkspace`文件打開項目,而不是`.xcodeproj`文件!
使用 CocoaPods 生成的` .xcworkspace `文件來打開工程,而不是以前的 `.xcodeproj `文件。
每次更改了 Podfile 文件,你需要重新執(zhí)行一次`pod update`命令。
至此CocoaPods安裝及簡單使用,完成!
>參考資料:
http://blog.devtang.com/2014/05/25/use-cocoapod-to-manage-ios-lib-dependency/
http://m.itdecent.cn/p/7ebf4ed97967
http://m.itdecent.cn/p/e0bebd18fcd9
http://m.itdecent.cn/p/43a268ba8f47
http://m.itdecent.cn/p/8115e7afce03
http://blog.slogra.com/post-663.html
http://blog.csdn.net/wm9028/article/details/51840759
排名不分先后, - -!