寫在前面 : 安裝CocoaPods的操作,自行g(shù)oogle,這里著重簡潔地使用,可以保存好隨時翻查,遇到更多無法解決錯誤可以Issues我
常用命令集合##
// -V 加載過程會打印錯誤
$ sudo gem install cocoapods -V
// 進入xx 文件夾
$ cd xx
// 初始化pod
$ pod install
// 打開文件夾/文件
$ open
// 找cocoaPod中的庫
$ pod search
// 查看cocoaPod的版本
$ pod --version
遇到的錯誤###
While executing gem ... (Gem::FilePermissionError)
// 這段東西讓我更新版本~
CocoaPods 1.0.0.beta.6 is available.
To update use: `gem install cocoapods --pre`
[!] This is a test version we'd love you to try.
// 于是我就更新, 然后報錯
$ gem install cocoapods --pre
// 第一個錯誤 FilePermissionError 沒有權(quán)限
Fetching: cocoapods-core-1.0.0.beta.6.gem (100%)
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
// 加上 sudo 再執(zhí)行一次給與根權(quán)限
$ sudo gem install cocoapods --pre
While executing gem ... (Errno::EPERM)
// 第二個錯誤
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/xcodeproj
// 一番搜索,更新,OS X 10.11系統(tǒng)上的問題大概就是缺小了這個文件 你可以 open /usr/bin/xcodeproj 打開看下
$ sudo gem install -n /usr/local/bin cocoapods 建一個文件咯
// 然后就成功了,
Successfully installed cocoapods-0.39.0
Parsing documentation for cocoapods-0.39.0
1 gem installed
Unable to satisfy the following requirements
// 第三個錯誤
[!] Unable to satisfy the following requirements:
- `AFNetworking (> 3.0)` required by `Podfile`
// they required a higher minimum deployment target. 必須給一個版本號, 編輯Podfile文件,給一個版本號
Specs satisfying the `AFNetworking (> 3.0)` dependency were found, but they required a higher minimum deployment target.
// 就是在platform :ios , ‘7.0’ 加上了這個7.0 7.0以上才能用
platform :ios , ‘7.0’
pod ‘AFNetworking’, ‘> 3.0’
Could not automatically select an Xcode project
// 第四個錯誤, 執(zhí)行 pod update的時候報這個錯, 意思是說你的Podfile文件找不到項目在哪里
[!] Could not automatically select an Xcode project. Specify one in your Podfile like so:
xcodeproj 'path/to/Project.xcodeproj'
// 解決辦法,打開編輯Podfile文件
// 告訴它你的項目文件在哪里
xcodeproj 'path/to/Project.xcodeproj' 也就是加上這句 'path/to/Project.xcodeproj' 這個是你項目的路徑
使用步驟 (整個步驟遇到的錯誤,記錄在上面了)##
零) 進入你的項目
$ cd xx\xx\xx
一) 在項目中創(chuàng)建Podfile文件
這個文件的作用
1, 它告訴 Cocoapods 你針對哪個平臺哪個版本
2, 它給 Cocoapods 一個你想要導(dǎo)入并設(shè)置的所有項目的列表。
$ touch Podfile
二) 打開Podfile文件,
// 第一種方法 : 打開文件編輯
$ open -e Podfile
// 第二種方法 : 用Pico編輯器編輯
$ pico
// 第三種方法 : 用vim編輯器
$ vim Podfile
三) 編輯Podfile文件
// 正如第一步Podfile文件的左右, 告訴他是用在IOS 還是MAC OS , 然后導(dǎo)入什么項目
platform : ios
pod 'AFNetworking'
四) 插一個步驟
不知道項目什么版本,可以先搜索一下
pod search AFNetWorking
五) 編輯完P(guān)odfile文件當(dāng)然要用,裝完xxxx.xcworkspace就應(yīng)該出來了,
$ pod install
其他操作##
找到cocoapods文件夾
// 去到cocoapods的文件夾~
Travins-IMac:DY cuiwenlong$ cd ~/.cocoapods
// 打開它 可以看到cocoapods的依賴樹 , Specs那堆就是
Travins-IMac:.cocoapods cuiwenlong$ open .
// 查看cocoapods的文件夾大小
Travins-IMac:.cocoapods cuiwenlong$ du -sh *
cocoapods文件夾
查看cocoapods版本,并且處理的一些操作
// 查看當(dāng)前安裝了哪些版本
$ gem list --local | grep cocoapods
//例如我, 裝了這么一堆版本
cocoapods (0.39.0)
cocoapods-core (1.0.0.beta.6, 0.39.0)
cocoapods-deintegrate (1.0.0.beta.1)
cocoapods-downloader (1.0.0.beta.2, 0.9.3)
cocoapods-plugins (1.0.0.beta.1, 0.4.2)
cocoapods-search (1.0.0.beta.1, 0.1.0)
cocoapods-stats (1.0.0.beta.3, 0.6.2)
cocoapods-trunk (1.0.0.beta.2, 0.6.4)
cocoapods-try (1.0.0.beta.3, 0.5.1)
// 卸載版本,先刪除已經(jīng)裝過的版本(需要你選擇卸載那個版本)
$ sudo gem uninstall cocoapods
// 或者強制刪除某個版本
$ gem uninstall cocoapods -v 1.0.0.beta.2, 0.6.4
// 這個常用命令哪里也有啦
$ sudo gem install cocoapods -v 0.35.0