CocoaPods
基本環境安裝
# 查看当前Ruby版本
ruby -v
# 安装rvm來對ruby進行版本管理
curl -L get.rvm.io | bash -s stable
source ~/.bashrc
source ~/.bash_profile
# 查看rvm版本
rvm -v
# 列出ruby可安装的版本信息
rvm list known
# 安装ruby, 建议选择最新的3.0.0版本
rvm install 3.0.0
# 設爲默認版本
rvm use 3.0.0 --default
# 查看源
gem sources -l
# 移除当前ruby的源
gem sources --remove https://rubygems.org/
# 设置当前ruby的源
gem sources -a https://gems.ruby-china.com/
# 更新gem
gem update --system
安裝CocoaPods
sudo gem install -n /usr/local/bin cocoapods
# 如果安装了多个Xcode使用下面的命令选择(一般需要选择最近的Xcode版本)
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
# 尝试安装AFNetworking
pod search AFNetworking
# wq退出
# 報錯:[!] Unable to find a pod with name, author, summary, or description matching 'AFNetworking'
# 查询repo 得到
pod repo
pod install
pod setup
# 报错:[!]No 'Podfile' found in the project directory.
# 查看这个文件夹:
cd ~/.cocoapods/repos
# 查无此路径,根据路径一步一步新建文件夹。/.cocoapods/repos/ 然后将库下载到本地:
git clone --depth 1 https://github.com/CocoaPods/Specs.git master
rm ~/Library/Caches/CocoaPods/search_index.json
pod search AFNetworking
使用CocoaPods
# 新建一個Xcode工程,在工程目錄下,創建Podfile文件
pod init
# 打開Podfile文件
open Podfile
# 添加依賴,並保存退出
pod 'MJExtension'
# Podfile的格式大概如下,其中'Test'为你的target的名字。
# platform :ios,'8.0'
# target 'Test' do
# pod 'MJExtension', '~> 3.0.13'
# end
# 開始下載安裝
pod install
# 更新
pod update
# 如果卡在Analyzing dependencies不动,原因是当执行以上两个命令的时候会升级CocoaPods的spec仓库,加一个参数可以省略这一步
pod install --verbose --no-repo-update
pod update --verbose --no-repo-update
# 其他
# 安装最新版cocoapods
sudo gem install cocoapods --pre
# 移除本地master
sudo rm -fr ~/.cocoapods/repos/master
# 移除本地缓存
sudo rm -fr ~/Library/Caches/CocoaPods/
# 重新setup,如果很慢可使用问题1的解决方法(git clone)
pod setup --verbose
# 移除trunk
pod repo remove trunk