cocoapods安裝

1、概要ios

iOS開發時,項目中會引用許多第三方庫,CocoaPods(https://github.com/CocoaPods/CocoaPods)能夠用來方便的統一管理這些第三方庫。git

 

2、安裝github

因爲網上的教程基本都大同小異,但細節之處還不是很完善,因此藉機會在這裏補充下:vim

注:要使用CocoaPods,那就要下載安裝它,而下載安裝CocoaPods須要Ruby環境xcode

 

一、Ruby環境搭建ruby

當前安裝環境爲Mac mini 10.8.5。Mac  OS自己自帶Ruby,但仍是更新一下保險,由於我第一次安裝在沒有更新Ruby的狀況下就失敗了。spa

a 查看下當前ruby版本:打開終端輸入 ruby -v(確實安裝了,不過用這個版本接下來工做失敗了,因此更新下ruby)code

ritekiMac-mini:PodTest lucky$ ruby -v  
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]  
ritekiMac-mini:PodTest lucky$   

b 更新rubyorm

 

終端輸入以下命令(把Ruby鏡像指向taobao,避免被牆,你懂得)blog

gem sources --remove https://rubygems.org/ 
gem sources -a https://ruby.taobao.org/ 
gem sources -l  (用來檢查使用替換鏡像位置成功)

ritekiMac-mini:~ lucky$ gem sources --remove https://rubygems.org/  
https://rubygems.org/ removed from sources  
ritekiMac-mini:~ lucky$ gem sources -a https://ruby.taobao.org/  
https://ruby.taobao.org/ added to sources  
ritekiMac-mini:~ lucky$ gem sources -l

二、下載安裝CocoaPods

終端輸入:sudo gem install cocoapods 

ritekiMac-mini:~ lucky$ sudo gem install cocoapods  
  
CHANGELOG:  
  
## 0.32.1  
  
##### Bug Fixes  
  
* Fixed the Podfile `default_subspec` attribute in nested subspecs.    
  [Fabio Pelosin][irrationalfab]  
 \ [#2050](https://github.com/CocoaPods/CocoaPods/issues/2050)  
  
  
Successfully installed cocoapods-0.32.1  
Installing ri documentation for cocoapods-0.32.1  
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rdoc/rdoc.rb:280: warning: conflicting chdir during another chdir block  
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rdoc/rdoc.rb:287: warning: conflicting chdir during another chdir block  
Done installing documentation for cocoapods after 10 seconds  
1 gem installed  

這樣就下載安裝好了CocoaPods

 

 

三、使用CocoaPods

a  新建一個項目,名字PodTest

b  終端中,cd到項目總目錄(注意:包含PodTest文件夾、PodTest.xcodeproj、PodTestTest的那個總目錄)

c  創建Podfile(配置文件)

接着上一步,終端輸入 vim Podfile

鍵盤輸入 i,進入編輯模式,輸入

platform :ios, '7.0' 
pod 'MBProgressHUD', '~> 0.8'

 

而後按Esc,而且輸入「 :」號進入vim命令模式,而後在冒號後邊輸入wq

注意:鍵盤輸入 :後,才能輸入wq。回車後發現PodTest項目總目錄中多一個Podfile文件

激動人心的時刻到了:肯定終端cd到項目總目錄,而後輸入 pod install,等待一會,大約3分鐘。

相關文章
相關標籤/搜索