1.安装Homebrew
2.安装CocoaPods
Homebrew安装成功之后,开始安装Cocoapods
2.1安装CocoaPods
使用Homebrew安装CocoaPods
brew install cocoapods
2.2 安装完成之后
pod setup
2.3 查询当前Pod版本与安装版本是否一致
brew info cocoapods
得出安装版本为1.12.0
pod --version
得出当前pod版本为1.5.2
两个版本不一致
2.4 修复版本不一致的问题
brew link --overwrite cocoapods
Homebrew重装cocoapods
2.5 测试是否可以搜寻三方库
pod search AFNetworking
如果出现
# [!] Unable to find a pod with name, author, summary, or description matching AFNetworking
可以进入 ~/Library/Caches/CocoaPods文件夹寻找并删除search_index.json,然后重新执行
pod search AFNetworking
3.CocoaPods使用方法
3.1 使用指定链接的三方库
使用仓库中的master分支:
pod 'AFNetworking', :git => 'https://github.com/xxx/AFNetworking.git'
使用仓库的其他分支:
pod 'AFNetworking', :git => 'https://github.com/xxx/AFNetworking.git' :branch => 'xxxx'
使用仓库的某个tag:
pod 'AFNetworking', :git => 'https://github.com/xxx/AFNetworking.git', :tag => '3.0.1'
3.2 source
有一些三方库并不是放在Git上面,可能是在一些公司自己的Git云上,这个时候需要把对应的source地址添加上去
source 'https://github.com/CocoaPods/Specs.git'
source 'https://cdn.cocoapods.org/'
source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'
cocoapods 官方source是隐式的需要的,一旦你指定了其他source 你就需要也把官方的指定上
3.3 自定义本地依赖库
- 使用本地文件
pod 'AFNetworking', :path => '/Users/abc/Destop/AFNetworking'
- 在你的本地pod库根目录添加xxx.podspec文件(AFNetworking.podspec)
- 编辑 xxx.podspec文件并将homepage修改为本地路径
- 执行 pod install