首先安装配置好 ruby
,CocoaPods
需要 Ruby
的版本大于 2.2.2,不然会报错:
Error installing pods: activesupport requires Ruby version >= 2.2.2
macOS 默认自带是 2.0 版本,所以需要升级。
$ brew update
$ brew install ruby
$ gem sources --remove https://rubygems.org/
# 据说淘宝源已停止维护,以前添加过淘宝源的删除
$ gem sources --remove https://ruby.taobao.org/
$ gem sources -a https://gems.ruby-china.org/
$ gem sources -l
*** CURRENT SOURCES ***
https://gems.ruby-china.org/
# 出现以上提示说明添加成功
$ sudo gem install -n /usr/local/bin cocoapods
若
Xcode
为预览版 ,在命令后边添加--pre
$ pod --version
$ sudo xcode-select --switch /Applications/Xcode.app
$ pod setup
# 本质是从 GitHub 克隆代码,一些国内镜像源停止更新,通过修改 host 加速 GitHub
$ pod search AFNetworking
可能出现错误
[!] Unable to find a pod with name, author, summary, or description matching `AFNetworking`
解决方法
$ rm ~/Library/Caches/CocoaPods/search_index.json
$ cd Desktop/swiftweahter
$ vi Podfile
platform :ios, '10.0'
use_frameworks!
target 'MyApp' do
pod 'AFNetworking', '~> 2.6'
pod 'ORStackView', '~> 3.0'
pod 'SwiftyJSON', '~> 2.3'
end
# 输入以上内容,target '****' do 单引号内填入你自己的项目名称
$ pod install --verbose --no-repo-update
打开项目用CocoaPodsDemo.xcworkspace
$ sudo gem update --system
# 待补充