1. 初始化
- 打開終端, 切換到項(xiàng)目根目錄(.xcodeproj 所在目錄)
cd(project home) - 初始化, 輸入
pod init
這時(shí)項(xiàng)目目錄中會(huì)生成一個(gè)
Podfile文件;
可以cat Podfile查看文件內(nèi)容
# Uncomment this line to define a global platform for your project
# platform :ios, '8.0'
# Uncomment this line if you're using Swift
# use_frameworks!
target 'CocoaPods測(cè)試' do
end
2. 編輯 Podfile 文件
- 將文件拖拽到 Xcode 圖標(biāo)上打開編輯;
- 終端
vi Podfile用 vim 編輯器編輯; - 其他編輯器 (不要 用默認(rèn)的文本編輯器打開, 引號(hào)保存會(huì)出錯(cuò))
#為注釋;- 打開第二行, 為項(xiàng)目指定平臺(tái)和系統(tǒng)版本
- 打開第四行, 如果是 Swift 項(xiàng)目
3. 引入第三方庫
在 GitHub 上搜索要引入的庫, 找到 Installation with CocoaPods, 復(fù)制 pod 命令
target 'CocoaPods測(cè)試' do
// 在這里添加要引入的第三方庫
// 例如:
pod 'AFNetworking', '~> 3.0'
end
- 保存并退出
4. 安裝
- 終端執(zhí)行:
pod install
此時(shí)終端顯示:
Updating local specs repositories更新本地倉庫, 時(shí)間較長, 可以添加參數(shù)禁用本地更新
pod install --no-repo-update
安裝成功后, 終端提示:
[!] Please close any current Xcode sessions and use
`CocoaPod測(cè)試.xcworkspace` for this project from now on.
使用 CocoaPods 生成的 .xcworkspace 文件來打開工程,而不是以前的 .xcodeproj 文件。
5. 更新
- 每次更改了 Podfile 文件,你需要重新執(zhí)行一次
pod update命令。
5.附 vim 簡單命令
相關(guān)文章:
參考:
- vi/vim基本使用方法: http://www.lupaworld.com/?uid-296380-action-viewspace-itemid-118973
- 用CocoaPods做iOS程序的依賴管理: http://blog.devtang.com/2014/05/25/use-cocoapod-to-manage-ios-lib-dependency/