心之所向萎津,素履以往抹镊,生如逆旅, 一葦以航颈渊。--cassiel社長??
A.cocoaPods的安裝
1.首先打開終端,輸入以下命令符升級Gem(可以省略)
sudo gem update -n /usr/local/bin —system
2.檢查Ruby源
gem sources -l
顯示現(xiàn)有ruby源:
**CURRENT SOURCES** https://rubygems.org/ https://ruby.taobao.org/
3.移除現(xiàn)有Ruby源:
gem sources--remove https://rubygems.org/
gem sources --remove https://ruby.taobao.org/ (不再維護(hù))
4.安裝阿里云Ruby鏡像:
gem sources -a http://rubygems-china.oss.aliyuncs.com
5.檢查是否成功安裝阿里ruby源:
$gem sources -l
顯示現(xiàn)有ruby源::
*** CURRENT SOURCES *** http://rubygems-china.oss.aliyuncs.com
6.:安裝cocoapods
$sudo gem install cocoapods
10.11之后系統(tǒng)要用命令:sudo gem install -n /usr/local/bin cocoapods
否則會報(bào)錯(cuò):ERROR: While executing gem ... (Errno::EPERM) Operation not permitted - /usr/bin/pod
7.:設(shè)置pod倉庫
cd ~/.cocoapods
//cd到.cocoapods文件夾
$ du -sh
//查看下載進(jìn)度
下載完畢后豌研,所占磁盤的大小在600-900M不等。
安裝成功標(biāo)志:
CocoaPods 1.2.0.beta.1 is available.
To update use: sudo gem install cocoapods --pre
[!] This is a test version we'd love you to try.For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.2.0.beta.1
Setup completed
B. CocoaPods的使用
1.需要查看一下CocoaPods是否安裝成功鬼佣,這時(shí)只需在終端輸入
pod search +第三方開源類庫的名字
+return確認(rèn)即可
例如:$ pod search AFNetworking
:wq
退出
2.進(jìn)入項(xiàng)目文件夾
$ cd + 項(xiàng)目文件夾路徑
(拖動(dòng)項(xiàng)目文件夾到終端自動(dòng)生成路徑)
3.創(chuàng)建Podfile 文件
$ touch Podfile
4.編輯Podfile文件
$ vim Podfile
5. 在Podfile文件里面進(jìn)行書寫
platform :ios, '8.0' #用來設(shè)置所有第三方庫所支持的iOS最低版本 target 'MyApp' do #MyApp 就是指項(xiàng)目名 pod ‘AFNetworking' end
ESC
取消輸入模式 :wq
保存并退出
6.編輯Podfile文件之后,保存退出晶衷,然后終端輸入命令:
$ pod install
Analyzing dependenciesDownloading dependenciesInstalling AFNetworking (3.1.0)Generating Pods projectIntegrating client project[!] Please close any current Xcode sessions and use xxxx.xcworkspace
for this project from now on.Sending statsPod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.
存在問題?:
使用CocoaPods來添加第三方類庫税迷,無論是執(zhí)行pod install還是pod update都卡在了Analyzing dependencies不動(dòng)
原因在于當(dāng)執(zhí)行以上兩個(gè)命令的時(shí)候會升級CocoaPods的spec倉庫箭养,加一個(gè)參數(shù)可以省略這一步哥牍,然后速度就會提升不少。加參數(shù)的命令如下:
pod install --verbose --no-repo-update
pod update --verbose --no-repo-update
[參考]http://blog.csdn.net/huang2009303513/article/details/42024163
打開項(xiàng)目文件夾發(fā)現(xiàn)自動(dòng)生成.xcworkspace工作站
7.以后需要添加、更新澡谭、刪除某個(gè)第三方庫蛙奖,只要編寫好Podfile文件外永,在終端輸入:
$ pod update --no-repo-update
穿梭山水間伯顶,化一羹緣骆膝!