iOS開發用CocoaPods做iOS程序的依賴管理

安裝方式異常簡單 , Mac 下都自帶 ruby,使用 ruby 的 gem 命令即可下載安裝:

$ sudo gem install cocoapods $ pod setup 

如果你的 gem 太老,可能也會有問題,可以嘗試用如下命令升級 gem:

sudo gem update --system 

另外,ruby 的軟件源 https://rubygems.org 因為使用的是亞馬遜的云服務,所以被墻了,需要更新一下 ruby 的源,使用如下代碼將官方的 ruby 源替換成國內淘寶的源:

gem sources --remove https://rubygems.org/ gem sources -a https://ruby.taobao.org/ gem sources -l 

還有一點需要注意,pod setup在執行時,會輸出Setting up CocoaPods master repo,但是會等待比較久的時間。這步其實是 Cocoapods 在將它的信息下載到 ~/.cocoapods目錄下,如果你等太久,可以試著 cd 到那個目錄,用du -sh *來查看下載進度。你也可以參考本文接下來的使用 cocoapods 的鏡像索引一節的內容來提高下載速度。

//////新建工程 CocoaPods

suchao:Desktop dllo$ cd CocoaPods
suchao:CocoaPods dllo$ ls
suchao:CocoaPods dllo$ pod init //創建podfile文件
suchao:CocoaPods dllo$ pod install

編輯文件

platform :ios
pod 'RegexKitLite-NoWarning', '~> 1.1.0'

platform :ios, '7.0'
pod "AFNetworking", "~> 2.0”
suchao:CocoaPods dllo$ pod install

//////////////////////////

生敲也可以 設置這個了 就可以直接索引出了
cocoapods 無法引入頭文件的問題
選擇工程的 Target -> Build Settings 菜單,找到\”User Header Search Paths\”設置項
新增一個值"$(PODS_ROOT)",并且選擇\”recursive\”,這樣xcode就會在項目目錄中遞歸搜索文件
屏幕快照 2015-10-29 上午11.57.48.png

使用 CocoaPods 的鏡像索引

所有的項目的 Podspec 文件都托管在https://github.com/CocoaPods/Specs。第一次執行pod setup時,CocoaPods 會將這些podspec索引文件更新到本地的 ~/.cocoapods/目錄下,這個索引文件比較大,有 80M 左右。所以第一次更新時非常慢,筆者就更新了將近 1 個小時才完成。

一個叫 akinliu 的朋友在 gitcafe 和 oschina 上建立了 CocoaPods 索引庫的鏡像,因為 gitcafe 和 oschina 都是國內的服務器,所以在執行索引更新操作時,會快很多。如下操作可以將 CocoaPods 設置成使用 gitcafe 鏡像:

pod repo remove master pod repo add master https://gitcafe.com/akuandev/Specs.git pod repo update 

將以上代碼中的 https://gitcafe.com/akuandev/Specs.git 替換成 http://git.oschina.net/akuandev/Specs.git 即可使用 oschina 上的鏡像。

、、、、、、、、、、、、

Last login: Thu Oct 29 11:09:47 on ttys003
suchao:~ dllo$ sudo gem install cocoapods
Password:
ERROR:  Could not find a valid gem 'cocoapods' (>= 0), here is why:
          Unable to download data from http://ruby.taobao.org/ - bad response Not Found 404 (http://ruby.taobao.org/latest_specs.4.8.gz)
suchao:~ dllo$ gem sougem sources --remove https://ruby.taobao.org
ERROR:  While executing gem ... (Gem::CommandLineError)
    Unknown command sougem
suchao:~ dllo$ gem sources --remove https://ruby.taobao.org/
source https://ruby.taobao.org/ not present in cache
suchao:~ dllo$ gem sources -l
*** CURRENT SOURCES ***

http://ruby.taobao.org/
suchao:~ dllo$ gem sources --remove https://rubygems.org/
source https://rubygems.org/ not present in cache
suchao:~ dllo$ gem sources -a https://ruby.taobao.org/
https://ruby.taobao.org/ added to sources
suchao:~ dllo$ sudo gem install cocoapods
Password:

Fetching: nap-1.0.0.gem (100%)
Successfully installed nap-1.0.0
Fetching: cocoapods-core-0.39.0.gem (100%)
Successfully installed cocoapods-core-0.39.0
Fetching: claide-0.9.1.gem (100%)
Successfully installed claide-0.9.1
Fetching: xcodeproj-0.28.2.gem (100%)
Successfully installed xcodeproj-0.28.2
Fetching: cocoapods-downloader-0.9.3.gem (100%)
Successfully installed cocoapods-downloader-0.9.3
Fetching: cocoapods-search-0.1.0.gem (100%)
Successfully installed cocoapods-search-0.1.0
Fetching: cocoapods-stats-0.6.2.gem (100%)
Successfully installed cocoapods-stats-0.6.2
Fetching: cocoapods-try-0.5.1.gem (100%)
Successfully installed cocoapods-try-0.5.1
Fetching: cocoapods-trunk-0.6.4.gem (100%)
Successfully installed cocoapods-trunk-0.6.4
Fetching: molinillo-0.4.0.gem (100%)
Successfully installed molinillo-0.4.0
Fetching: cocoapods-0.39.0.gem (100%)
Successfully installed cocoapods-0.39.0
Parsing documentation for nap-1.0.0
Installing ri documentation for nap-1.0.0
Parsing documentation for cocoapods-core-0.39.0
Installing ri documentation for cocoapods-core-0.39.0
Parsing documentation for claide-0.9.1
Installing ri documentation for claide-0.9.1
Parsing documentation for xcodeproj-0.28.2
Installing ri documentation for xcodeproj-0.28.2
Parsing documentation for cocoapods-downloader-0.9.3
Installing ri documentation for cocoapods-downloader-0.9.3
Parsing documentation for cocoapods-search-0.1.0
Installing ri documentation for cocoapods-search-0.1.0
Parsing documentation for cocoapods-stats-0.6.2
Installing ri documentation for cocoapods-stats-0.6.2
Parsing documentation for cocoapods-try-0.5.1
Installing ri documentation for cocoapods-try-0.5.1
Parsing documentation for cocoapods-trunk-0.6.4
Installing ri documentation for cocoapods-trunk-0.6.4
Parsing documentation for molinillo-0.4.0
Installing ri documentation for molinillo-0.4.0
Parsing documentation for cocoapods-0.39.0
Installing ri documentation for cocoapods-0.39.0
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/latest_specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/latest_specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
WARNING:  Unable to pull data from 'http://ruby.taobao.org/': bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
11 gems installed
suchao:~ dllo$ 
suchao:~ dllo$ pod setup
Setting up CocoaPods master repo
Setup completed
suchao:~ dllo$ cd D
Desktop/   Documents/ Downloads/ 
suchao:~ dllo$ cd Desktop/
suchao:Desktop dllo$ ls
0710DistributionCer.p12
AdobeFlashPlayer_19_a_install-2.dmg
CarProfile.mobileprovision
CertificateName.p12
CertificateName.pem
CertificateSigningRequest.certSigningRequest
CocoaPods
Night
PUSHOrcal123.mobileprovision
aps_development.cer
dash
iconfont-xiala.png
ios開班用誤刪
logo
tabBar圖標
tupbiao 
夜間
桌面
高亮
點擊Section下拉Cell
點擊Section下拉cell 2
啟動頁
引導頁
搖一搖 2
引導頁(完整版)
引導頁(最終版)
啟動頁Car
全屏瀏覽
可可旅行
課程代碼
課程課件
愛車達人 2
屏幕快照 2015-10-28 下午8.37.27.png
屏幕快照 2015-10-28 下午8.37.36.png
屏幕快照 2015-10-29 上午9.06.05.png
愛車達人.zip
未命名文件夾
愛車資訊截圖
未命名文件夾 2
suchao:Desktop dllo$ cd CocoaPods
suchao:CocoaPods dllo$ ls
CocoaPods CocoaPodsTests
CocoaPods.xcodeproj CocoaPodsUITests
suchao:CocoaPods dllo$ vim podfile
suchao:CocoaPods dllo$ pod install

[!] Invalid `Podfile` file: undefined method `tform' for #<Pod::Podfile:0x007fddebb1a4d8>. Updating CocoaPods might fix the issue.

 #  from /Users/dllo/Desktop/CocoaPods/Podfile:1
 #  -------------------------------------------
 >  tform :ios
 #  pod 'RegexKitLite-NoWarning', '~> 1.1.0'
 #  -------------------------------------------
suchao:CocoaPods dllo$ vim podfile
suchao:CocoaPods dllo$ pod install
Updating local specs repositories
Analyzing dependencies
Downloading dependencies
Installing AFNetworking (2.6.1)
Installing RegexKitLite-NoWarning (1.1.0)
Generating Pods project
Integrating client project

[!] Please close any current Xcode sessions and use `CocoaPods.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There are 2 dependencies from the Podfile and 2 total
pods installed.
suchao:CocoaPods dllo$ 
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 229,732評論 6 539
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 99,214評論 3 426
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 177,781評論 0 382
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,588評論 1 316
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 72,315評論 6 410
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,699評論 1 327
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,698評論 3 446
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,882評論 0 289
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 49,441評論 1 335
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 41,189評論 3 356
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,388評論 1 372
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,933評論 5 363
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,613評論 3 348
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 35,023評論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,310評論 1 293
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 52,112評論 3 398
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 48,334評論 2 377

推薦閱讀更多精彩內容

  • 原文地址:用CocoaPods做iOS程序的依賴管理 - 唐巧的技術博客 CocoaPods簡介 每種語言發...
    Mark_Lin閱讀 310評論 0 1
  • 轉載:唐巧的技術博客 CocoaPods 簡介 每種語言發展到一個階段,就會出現相應的依賴管理工具,例如 Java...
    喜歡就可以閱讀 255評論 0 1
  • 這篇文章主要是轉載唐巧的,文章底部也有大神寫的原文連接,其中在有些地方根據自己的使用稍微修改了一點點,當然,不是說...
    devZhang閱讀 565評論 1 0
  • 老婆一下午談成功了四個單子,這相當于上個月業務量的總和,所以今天特別高興。 說來也奇怪,我回成都之后,來找老婆做甜...
    承謙閱讀 208評論 0 0
  • 2.神秘男孩 一周時間,已讓琉璃適應了千金小姐這個身份。 時間:早上,地點:醫院—— “女兒,我們來了。”琉璃媽媽...
    絨染閱讀 249評論 0 1