1.更新gem
sudo gem update --system
2.替換源
gem sources --remove https://ruby.taobao.org/ 執(zhí)行失敗的話,可以跳過該句不管沧踏,先移除淘寶的源锉走,現(xiàn)在無效了
gem sources -a https://rubygems.org/
gem sources -l // 查看到前連接點源
3.安裝
$ sudo gem install cocoa pods
macOS 10.11以后用
sudo gem install -n /usr/local/bin cocoapods
$ pod setup
4.安裝完畢
到此cocoa pod安裝完畢锐想,如有問題參考8,9绞幌;以下為實例應(yīng)用及問題
5.查看下載進(jìn)度
1.png
Cocoapods在將它的信息下載到~/.cocoapods目錄下疾掰,如果你等太久,可以試著cd到那個目錄听皿,用du -sh *來查看下載進(jìn)度咕别。
2.png
6.到指定工程下與.xcodeproj同級目錄建 Podfile文件沒有后綴,并使用vim編輯
內(nèi)容例子:
platform :ios
pod 'JSONKit', '~> 1.4'
pod 'Reachability', '~> 3.0.0'
pod 'ASIHTTPRequest'
pod ‘RegexKitLite'
7.保持在.xcodeproj同級目錄下
新建Podfile 使用 pod install
已有Podfile 使用 pod update
8.CocoaPods 在執(zhí)行pod install和pod update時,會默認(rèn)先更新一次podspec索引写穴。使用--no-repo-update參數(shù)可以禁止其做索引更新操作(保持在.xcodeproj同級目錄下)
pod install --no-repo-update
pod update --no-repo-update
9.加載 ReactiveCocoa Podfile文件配置例子
platform :ios,'8.0'
use_frameworks!
pod 'ReactiveCocoa', '~> 3.0.0’
10.為工程多target添加依賴支持
(1) 編輯Podfile文件
(a) 所有target使用相同的第三方依賴配置
platform :ios,'6.0'
link_with 'tbHD','tbHD_store' // target名稱
pod 'ReactiveCocoa', '~> 2.5'
pod 'SDWebImage', '~> 3.7.3'
pod 'objective-zip', '~> 1.0'
pod 'UMengFeedback', '~> 2.3.4'
pod 'UMengAnalytics'
pod 'HTProgressHUD', '~> 0.2.1'
pod 'WebViewJavascriptBridge', '~> 5.0'
(b) 不同的target使用不同的第三方依賴配置
platform :ios,'6.0'
target:tbHD do
pod 'ReactiveCocoa', '~> 2.5'
end
target:tbD_store do
pod 'UMengAnalytics'
end
(2) 保存Podfile,重新運行pod install。
11.問題解決
如果上面因為權(quán)限問題安裝失敗雌贱,必須每次都要刪除
rm -rf /Users/loginnanme/Library/Caches/CocoaPods/
12.警告
The `tbtuiHD [Release]` target overrides the `OTHER_LDFLAGS` build
setting defined in `Pods/Target Support Files/Pods/Pods.release.xcconfig'.
This can lead to problems with the CocoaPods installation
項目中定義`PODS_ROOT` 和 `Other Linker Flags`的地方啊送,
把他們的值用`$(inherited)`替換掉,進(jìn)入終端欣孤,執(zhí)行
pod update