今天創(chuàng)建項目時彈出Cocoapods需要升級提示

順便記錄下升級步驟吧:
1.安裝/升級RVM(Ruby Version Manager)
- 先查看RVM版本, 輸入命令 rvm -v (注意:輸入命令時 最后一位不要多空格,否則會提示找不到)

提示 -bash: rvm: command not found,說明本機沒有安裝RVM
則需要安裝RVM:
1.1 終端輸入命令 curl -L get.rvm.io | bash -s stable
出現(xiàn)此圖,說明已經(jīng)安裝并使用RVM了,為了安全起見先執(zhí)行 rvm -v 命令測試一下,就可以看到當前RVM版本啦
- 1.2 用RVM升級Ruby,輸入 ruby -v ,查看當前Ruby版本,
輸入 rvm list known 查看Ruby所有版本 - 1.3 選擇較高版本安裝,執(zhí)行 rvm install 2.4.0 ,安裝時報錯,嘗試多此還是這樣

這是由于本機安裝了兩個Xcode導(dǎo)致
卸載低版本Xcode后再次執(zhí)行rvm install 2.4.0 后依然報錯,報錯內(nèi)容變了,如下
根據(jù)提示 configure: error: clang version 3.0 or later is required,我猜測Xcode的命令行工具設(shè)置有問題,打開Xcode,果然如此
-
重新設(shè)置下
再次執(zhí)行安裝命令,成功安裝

至此,RVM終于安裝成功了
2.安裝新版Cocoapods,執(zhí)行命令 sudo gem install cocoapods
3.執(zhí)行命令 sudo gem install cocoapods

4.繼續(xù)執(zhí)行命令 sudo gem install cocoapods 時可能會報錯,應(yīng)該執(zhí)行 sudo gem install -n /usr/local/bin cocoapods
- 繼續(xù)執(zhí)行命令 sudo gem install cocoapods命令報錯
-
執(zhí)行 sudo gem install -n /usr/local/bin cocoapods 安裝成功
此時新版cocoapods安裝成功,輸入 pod 命令測試下
此時說明可以正常使用了
補充
-
使用新版cocoapods后podfile文件寫法跟以前不一樣了
例如,之前是這樣寫的
執(zhí)行 pod install 則會報錯
- 正確寫法應(yīng)該是
platform :ios, '8.0'
target 'ZQBlockchainWallet' do
pod 'IQKeyboardManager', '~> 4.0.6'
end
執(zhí)行 pod install ,成功
如果你的項目是swift項目,執(zhí)行上面寫法可能會出現(xiàn)如下錯誤

解決辦法是在 podfile加上 use_frameworks!
platform :ios, '8.0'
target 'ZQBlockchainWallet' do
pod 'IQKeyboardManager', '~> 4.0.6'
use_frameworks! // 加上這句
end
以上寫法也可以這樣
platform :ios, '8.0'
def pods
pod 'AFNetworking', '~> 3.1.0'
pod 'SDWebImage', '~> 3.7.6'
pod 'SVProgressHUD', '~> 2.0.3'
pod 'SnapKit', '~> 3.1.2'
end
target 'MyAppProjName' do
pods
use_frameworks!
end
產(chǎn)生這種錯誤的原因是 Reference: http://blog.cocoapods.org/CocoaPods-0.36/
Because Apple doesn't let you build static libraries that contain Swift. Unlike Objective-C, Apple doesn't ship the Swift standard runtime libraries with iOS. This decouples the language version from the platform version. When you build an app with Swift, you're responsible yourself to ship them. By default, Xcode uses swift-stdlib-tool to handle copying the Swift runtime dylibs, but the tooling falls short when attempting to ship frameworks that use Swift with an app that is Objective-C only. Your app executable and the frameworks you ship will all use the same set of dylibs, which are embedded into the Frameworks subdirectory of the application bundle.
當項目中有多個target時,可以這樣寫
use_frameworks!
target 'YourProjectName' do
pod 'SwiftyJSON', '~> 2.1'
pod 'SwiftSpinner', '~> 0.6'
pod 'Alamofire', '~> 1.1'
pod 'SuperRecord', '~> 1.2'
// all other pods goes here
end
target 'YourProjectName1' do
end
target 'YourProjectName2' do
end












