1.開啟 terminal
2.移除現有 ruby 預設源
$ gem sources --remove
3.使用新的源
$ gem sources -a
4.驗證新源是否替換成功
$ gem sources -l
5.安裝 cocoapods
$ sudo gem install cocoapods
$ pod setup
備註:蘋果系統公升級 os x el capitan 後安裝改為:
$ sudo gem install -n /usr/local/bin cocoapods
$ pod setup
6.更新 gem
$ sudo gem update --system
7.新建工程,並在終端用 cd 指令到資料夾內
$ pod search 第三方
8.新建 podfile 檔案
$ touch podfile
9.編輯 podfile 檔案,並寫入要新增的第三方庫
platform:ios, '8.0'
pod 'afnetworking', '~> 2.3.1'<-------第三方
10.匯入第三方庫
$ pod install
11.退出終端
error 1:
error fetching
bad response not found 404 (
解決方案:把安裝流程中 $ gem sources -a
改為:$ gem sources -a
error: while executing gem ... (errno::eperm)
operation not permitted - /usr/bin/pod
解決方案:蘋果系統公升級 os x el capitan 後會出現的外掛程式錯誤,將安裝流程 5.安裝 cocoapods 的 sudo gem install cocoapods
改為 sudo gem install -n /usr/local/bin cocoapods
[!] unable to satisfy the following requirements:
- `afnetworking (~> 2.3.1)` required by `podfile`
specs satisfying the `afnetworking (~> 2.3.1)` dependency were found, but they required a higher minimum deployment target.
解決方案:podfile 檔案 中 platform:ios, 『8.0』 後邊的 8.0 是平台版本號 ,一定要加上
error4:
――――――――――
markdown template ――――――――――
### report
* what did you do?
### stack
```cocoapods : 0.29.0
ruby : ruby 2.0.0p247 (2013-06-27 revision 41674) [universal.x86_64-darwin13]
rubygems : 2.1.11
host : mac os x 10.9.2 (13c64)
xcode : 5.1 (5b130a)
ruby lib dir : /system/library/frameworks/ruby.framework/versions/2.0/usr/lib
repositories : master - @ bd6736d07b16c98ab7a1dae04697cae002f25a9b
```### podfile
```ruby
platform :ios,'8.0'
pod 'mbprogresshud', '~> 0.8'
```### error
```
/system/library/frameworks/ruby.framework/versions/2.0/usr/lib/ruby/2.0.0/psych.rb:205:in `parse'
/system/library/frameworks/ruby.framework/versions/2.0/usr/lib/ruby/2.0.0/psych.rb:205:in `parse_stream'
/system/library/frameworks/ruby.framework/versions/2.0/usr/lib/ruby/2.0.0/psych.rb:153:in `parse'
/system/library/frameworks/ruby.framework/versions/2.0/usr/lib/ruby/2.0.0/psych.rb:129:in `load'
/system/library/frameworks/ruby.framework/versions/2.0/usr/lib/ruby/2.0.0/psych.rb:299:in `block in load_file'
/system/library/frameworks/ruby.framework/versions/2.0/usr/lib/ruby/2.0.0/psych.rb:299:in `open'
/system/library/frameworks/ruby.framework/versions/2.0/usr/lib/ruby/2.0.0/psych.rb:299:in `load_file'
/library/ruby/gems/2.0.0/gems/cocoapods-0.29.0/lib/cocoapods/sources_manager.rb:261:in `version_information'
/library/ruby/gems/2.0.0/gems/cocoapods-0.29.0/lib/cocoapods/sources_manager.rb:222:in `repo_compatible?'
/library/ruby/gems/2.0.0/gems/cocoapods-0.29.0/lib/cocoapods/sources_manager.rb:281:in `master_repo_functional?'
/library/ruby/gems/2.0.0/gems/cocoapods-0.29.0/lib/cocoapods/command.rb:39:in `parse'
/library/ruby/gems/2.0.0/gems/claide-0.4.0/lib/claide/command.rb:179:in `parse'
/library/ruby/gems/2.0.0/gems/cocoapods-0.29.0/lib/cocoapods/command.rb:38:in `parse'
/library/ruby/gems/2.0.0/gems/claide-0.4.0/lib/claide/command.rb:211:in `run'
/library/ruby/gems/2.0.0/gems/cocoapods-0.29.0/lib/cocoapods/command.rb:51:in `run'
/library/ruby/gems/2.0.0/gems/cocoapods-0.29.0/bin/pod:24:in `'
/usr/bin/pod:23:in `load'
/usr/bin/pod:23:in `'
```――――――――――
template end ――――――――――
[!] oh no, an error occurred.
search for existing github issues similar to yours:
if none exists, create a ticket, with the template displayed above, on:
don't forget to anonymize any private data!
解決方案:
$ sudo rm -rf ~/.cocoapods/repos/master
$ pod setup
CocoaPods安裝及使用
cocoapods是乙個負責管理ios專案中第三方開源庫的工具。cocoapods的專案原始碼在github上管理。在ios開發中,我們一定會經常使用到各種各樣的第三方開源庫,使用這些開源庫的時候,需要引入原始碼 進行設定 引入其他framework,還有版本的更新 這些工作沒有技術含量而且複雜。這...
cocoapods安裝及使用
mac自帶ruby,輸入下面命令 ruby version如果有類似如下顯示 ruby 2.0.0p648 2015 12 16 revision 53162 universal.x86 64 darwin16 gem sources remove等有反應了,輸入 gem sources agem ...
CocoaPods的安裝及使用
在ios開發過程中,我們不可避免地使用第三方類庫,但是類庫的迴圈引用 更新等用手動操作的話會很費時和費力,所以,我們需要一款類庫管理工具來管理我們使用的第三方類庫。cocoapods是ios開發中最常用的類庫管理工具。而且,絕大多數開源類庫都支援cocoapods。1.cocoapods的依賴環境 ...