Cocoapods 的安裝 及使用
最近公司要開個新專案。所以重新安裝下電腦上的Cocoapods。具體的執行步驟如下 ,希望對大家有所幫助。
首先,開啟終端輸入視窗。(本文中出現的$都不需要輸入,只是為了方便大家知道哪個是命令)
檢查當前的gem source.
$ gem sources -l
如果沒有 任何的ruby源 命令列反饋提示為:command not found; //這種情況一般表現在之前電腦上沒裝過Cocoapods的情況。
如果電腦上之前安裝過Cocoapods,命令列反饋提示為:
*** CURRENT SOURCES ***
https://rubygems.org/
或者*** CURRENT SOURCES ***
https://taobao.org/ //這裡 這兩個地址為兩個不同地址的映象檔案。一個是ruby的映象檔案 一個是淘寶的映象檔案。
如果 你曾經安裝的是第一種情況下的映象檔案的話 ,建議刪除,重新安裝淘寶的映象檔案 (因為第一個網址被我大天朝無情遮蔽了 你們懂的 當然如果你有可用的VPN 應該也可以下載第一種,這裡我下載的是第二種)。
如果命令列 反饋出的是第一種情況 :輸入命令
$gem sources --remove https://rubygems.org/ //移除ruby映象檔案
正常的命令列反饋為:
https://rubygems.org/ removed from sources
$gem sources -a https://ruby.taobao.org/ //安裝淘寶映象檔案(這裡注意:如果 你電腦上沒裝過Cocoapods 從這一步開始)
正常的命令列反饋為:
https://ruby.taobao.org/ added to sources
以下將執行安裝Cocoapods的操作(到這一步 無論是哪種情況 都已經安裝了淘寶的映象檔案,所以以下步驟適用所有情況)命令列執行:
$sudo gem install cocoapods //執行安裝下載Cocoapods命令
如果 你電腦上有密碼 會叫你輸入密碼 注意 你輸入的密碼 預設是不顯示的 直接輸入密碼 回車即可
輸入密碼會等待一段時間 命令列反饋為:
liuxhdeMBP:~ liuxh$ sudo gem install cocoapods
Password:
Fetching: i18n-0.7.0.gem (100%)
Successfully installed i18n-0.7.0
Fetching: thread_safe-0.3.5.gem (100%)
Successfully installed thread_safe-0.3.5
Fetching: tzinfo-1.2.2.gem (100%)
Successfully installed tzinfo-1.2.2
Fetching: minitest-5.8.4.gem (100%)
Successfully installed minitest-5.8.4
Fetching: activesupport-4.2.5.2.gem (100%)
Successfully installed activesupport-4.2.5.2
Fetching: nap-1.1.0.gem (100%)
Successfully installed nap-1.1.0
Fetching: fuzzy_match-2.0.4.gem (100%)
Successfully installed fuzzy_match-2.0.4
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: colored-1.2.gem (100%)
Successfully installed colored-1.2
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-plugins-0.4.2.gem (100%)
Successfully installed cocoapods-plugins-0.4.2
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: netrc-0.7.8.gem (100%)
Successfully installed netrc-0.7.8
Fetching: cocoapods-trunk-0.6.4.gem (100%)
Successfully installed cocoapods-trunk-0.6.4
Fetching: molinillo-0.4.4.gem (100%)
Successfully installed molinillo-0.4.4
Fetching: escape-0.0.4.gem (100%)
Successfully installed escape-0.0.4
Fetching: cocoapods-0.39.0.gem (100%)
Successfully installed cocoapods-0.39.0
Parsing documentation for i18n-0.7.0
Installing ri documentation for i18n-0.7.0
Parsing documentation for thread_safe-0.3.5
Installing ri documentation for thread_safe-0.3.5
Parsing documentation for tzinfo-1.2.2
Installing ri documentation for tzinfo-1.2.2
Parsing documentation for minitest-5.8.4
Installing ri documentation for minitest-5.8.4
Parsing documentation for activesupport-4.2.5.2
unable to convert "\x84" from ASCII-8BIT to UTF-8 for lib/active_support/values/unicode_tables.dat, skipping
Installing ri documentation for activesupport-4.2.5.2
Parsing documentation for nap-1.1.0
Installing ri documentation for nap-1.1.0
Parsing documentation for fuzzy_match-2.0.4
Installing ri documentation for fuzzy_match-2.0.4
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 colored-1.2
Installing ri documentation for colored-1.2
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-plugins-0.4.2
Installing ri documentation for cocoapods-plugins-0.4.2
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 netrc-0.7.8
Installing ri documentation for netrc-0.7.8
Parsing documentation for cocoapods-trunk-0.6.4
Installing ri documentation for cocoapods-trunk-0.6.4
Parsing documentation for molinillo-0.4.4
Installing ri documentation for molinillo-0.4.4
Parsing documentation for escape-0.0.4
Installing ri documentation for escape-0.0.4
Parsing documentation for cocoapods-0.39.0
Installing ri documentation for cocoapods-0.39.0
21 gems installed //這一段程式碼 就是表示 你下載成功了
然後 執行命令:$pod setup //設定 cocoapods
執行完這句 命令列提示為:
Setting up CocoaPods master repo //這裡會停留一段時間 等待電腦設定完成即可。
當電腦設定完以後 會提示:
CocoaPods 1.0.0.beta.4 is available.
To update use: `gem install cocoapods --pre`
[!] This is a test version we'd love you to try.
For more information see http://blog.cocoapods.org
and the CHANGELOG for this version http://git.io/BaH8pQ.
Setup completed
到這裡 恭喜你! 您已成功安裝Cocoapods。如何使用CocoaPods:
1.在Xcode上新建一個工程,在終端中進入程式根目錄下,輸入:pod init
這裡會建立一個podfile檔案;
2.進入podfile檔案,可以利用命令,vi podfile ----> pod 'AFNetworking'-->esc --->shift + 雙擊Z ,這時退出並儲存了;(注:如果直接開啟檔案輸入pod ‘AFNetworking’可能會出錯,建議使用終端輸入)
3.輸入:pod install ,這時請耐心等待下載,等下載好。開啟工程 那麼這個庫就已經存在你的專案中了
5.啟動工程的時候選擇使用pod生成的那個工程名。
6.刪除cocoaPods中的某個類庫
如果自己不想使用某個類庫後,想刪除某個三方庫,那麼我們就需要重新配置podfile檔案,在podfile檔案中直接開啟,刪除對應的文字就可以解決掉,比如直接把pod ‘AFNetworking’刪除即可,然後執行pod install
7.刪除cocoaPods我如果覺得不想使用cocoaPods,我想刪除,那麼我需要刪除一下檔案
刪除工程資料夾下的Podfile、Podfile.lock和Pods資料夾。
刪除xcworkspace檔案。
開啟xcodeproj檔案,刪除專案中的libpods.a和Pods.xcconfig引用: