iOS開發日記22-CocoaPods,ios22-cocoapods

來源:互聯網
上載者:User

iOS開發日記22-CocoaPods,ios22-cocoapods

今天博主有一個CocoaPods的需求,遇到了一些困痛點,在此和大家分享,希望能夠共同進步.

CocoaPods是一個第三方庫的管理工具,在團隊開發時,不建議大家使用CocoaPods,但是在獨立開發時,十分推薦.

安裝CocoaPods,我們首先需要FQ.

在終端敲入

$ gem sources --remove https://rubygems.org/

等有反應後再敲入$ gem sources -a http://ruby.taobao.org/

然後測試下是真的可以了麼,敲入
$ gem sources -l
*** CURRENT SOURCES ***http://ruby.taobao.org/

ok,FQ成功.

第一步:安裝

CocoaPods是跑在Ruby的軟體,安裝可能需要幾分鐘,開啟你的終端輸入:

sudo gem install cocoapods

如果成功 會有一個 Successfully installed cocoaPods的提示 ,

然後輸入

pod setup

如果顯示Ruby環境不夠新,你的機子就跟我的機子一樣老,來升級吧

sudo gem update --system

好你的Ruby升級完了,可以重複之前的步驟了。

第二步:建立一個 Podfile 檔案

繼續在你的終端操作,先使用 cd 操作 進入你的項目目錄例如 cd ~/desktop/HelloWord

在這個目錄下建立檔案

touch Podfile 然後斷行符號繼續輸入open -e Podfile 這時將直接開啟一個空的檔案先在這開啟著不要管一會會處理的

第三步:搜尋庫

現在就需要找到你要的第三方庫了,在終端裡輸入(以尋找Reachability為例)

pod search Reachability

 終端會有和這個搜尋結果相近的選項(樣本如下)

-> KSReachability (1.3)
A better iOS & Mac reachability for a modern age.
- Homepage: https://github.com/kstenerud/KSReachability
- Source: https://github.com/kstenerud/KSReachability.git
- Versions: 1.3, 1.1, 1.0, 0.0.1 [master repo]

-> NPReachability (0.1.0)
Reachability without the suck.
- Homepage: https://github.com/Abizern/NPReachability
- Source: https://github.com/Abizern/NPReachability.git
- Versions: 0.1.0 [master repo]

-> Reachability (3.1.0)
ARC and GCD Compatible Reachability Class for iOS and OS X. Drop in
replacement for Apple Reachability.
- Homepage: https://github.com/tonymillion/Reachability
- Source: https://github.com/tonymillion/Reachability.git
- Versions: 3.1.0, 3.0.0, 2.0.5 [master repo]

第四步:在剛才開啟的空白Podfile中加入你想要的,

platform :ios8.0  (這表示系統平台版本)pod 'Reachability', '3.1.0'   (庫的名稱  庫的版本號碼)
(如果是多個就繼續羅列即可):
platform :ios8.0
pod 'JSONKit','1.4'
pod 'Reachability','3.0.0'

第五步:將這個寫入資料的 Podfile儲存後關閉

第六步:在終端輸入

pod install

然後終端會有顯示 樣本:

[!] From now on use `name.xcworkspace'.

最後:是的 就像你看到的,你開啟工程需要雙擊 .xcworkspace 這個工程,而不是之前的xcodeproj!!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.