咱們都知道第三方庫,通常使用cocoapods管理,cocoapods在咱們IOS開發中有着很大的做用。ios
好了,如今看下它的安裝步驟: 1.打開終端,輸入ruby
sudo gem install cocoapods
結果: bash
WARNING: Improper use of the sudo command could lead to data loss or the deletion of important system files. Please double-check your typing when using sudo. Type "man sudo" for more information. To proceed, enter your password, or type Ctrl-C to abort. Password: (輸入本機的密碼)
2.輸入密碼後,按回車建,等待。。。spa
結果:code
ERROR: Could not find a valid gem 'cocoapods' (>= 0), here is why: Unable to download data from https://rubygems.org/ - Errno::ETIMEDOUT: Operation timed out - connect(2) (https://rubygems.org/latest_specs.4.8.gz) ERROR: Possible alternatives: cocoapods
3.輸入orm
gem sources --remove https//rubygems.org/
按回車建 結果:blog
source https//rubygems.org/ not present in cache
4.輸入開發
gem sources -a http://ruby.taobao.org/
結果:rem
http://ruby.taobao.org/ added to sources
5.輸入(刪除一些沒必要要的)it
gem sources --remove https://rubygems.org/
結果:
https://rubygems.org/ removed from sources
6.輸入
gem sources -l
結果:
*** CURRENT SOURCES *** http://ruby.taobao.org/
注意:因爲升級 10.11後,淘寶升級http協議到https,須要刪除http,添加https(若是系統版本是10.11以前的,這一步能夠跳過。版本是10.11,跳過步驟4,就沒必要要remove http。)
輸入(刪除http)
gem sources --remove http://ruby.taobao.org/
結果:
http://ruby.taobao.org/ removed from sources
輸入(添加https)
gem sources --add https://ruby.taobao.org/
結果:
https://ruby.taobao.org/ added to sources
7.輸入
pod setup
結果:
-bash: pod: command not found
8.從新執行:
sudo gem install cocoapods
結果
Password: (輸入本機的密碼) 結果; 是一串數據更新。。。(等待)
9.輸入
pod setup
結果
Setting up CocoaPods master repo Setup completed
10.(搜索,不區分大小寫,寫得越詳細也好,找到路徑越精確) 輸入
pod search afnetwork
結果: 一串關於(afnetwork)的東西(搜到的結果)
11.到了這一步,咱們須要把建好本身的工程,而後在終端輸入 cd(記得cd後面要空格)把工程文件拖到這來。按回車(之後就能夠直接忽略上面10個步驟,直接開始pod)
12.輸入
vi Podfile
按‘i’進入編輯狀態,下面是一些你要編輯的內容:(也就是你的要更新那些第三方庫)
1 platform:ios 2 pod 'Reachability','~>3.1.0' 3 4 platform:ios,'6.0' 5 pod 'AFNetworking','~> 2.3.1'
編輯好以後,按‘esc’,而後按‘shift+:’,鍵入 wq(保存退出)
13.更新,輸入
pod update
14.安裝,輸入
pod install
完成上面步驟後(工程會多一些文件),到工程文件打開.xcworkspace的文件,就能夠了,須要用到什麼,就添加頭文件就OK了。
補充1:當咱們有時候用了某個第三方,後期以爲不爽或者很差用,想刪除掉,這裏也能夠用cocoapods處理。
步驟:
1.在終端輸入 cd 把工程文件(須要刪除第三方庫的工程)拖到這來,按回車。
2.輸入
vi Podfile
3.好比要刪除「Reachability」,
1 platform:ios 2 pod 'Reachability','~>3.1.0' (刪掉這一行,其餘不改) 3 4 platform:ios,'6.0' 5 pod 'AFNetworking','~> 2.3.1'
刪掉 pod 'Reachability','~>3.1.0'後,保存退出。
執行上面的13和14 步驟,以後到工程文件打開.xcworkspace的文件,你會發現pods少了「Reachability」。
補充2:消除三方庫的警告
若是是第三方庫pod以後會有警告,你在本身的項目中改了以後,pod下做者更新一下又白改了,因此這裏介紹一種簡單粗暴的方法:直接讓第三方庫的警告不顯示
就是在podfile文件裏面加上一行指令 。
inhibit_all_warnings!
若是仍是沒有消除警告,你我的又不想讓它顯示,能夠加入預編譯指令
#pragma clang diagnostic push #pragma clang diagnostic ignored"-Wunused-variable" //這裏是會報警告的代碼 #pragma clang diagnostic pop
「-Wunused-variable」的意思是有的東西你實例化了可是沒有使用上。