1、安装pod
// 命令行安装
sudo gem install cocoapods
// 或在官网下载APP安装
安装失败时,可能是由于镜像源出了问题
// 查看镜像源
$ gem sources -l
// 删除原有的镜像源
$ gem sources --remove https://rubygems.org/
// 添加国内最新的镜像源
$ gem source -a https://gems.ruby-china.org/
2、导入第三方库
在项目中添加要使用的第三方库,如:AFNetworking、SYImageBrowser、IQKeyboardManager等。
操作步骤:操作时需要在项目目录下进行
(1)进入当前项目目录,使用命令 cd xx,如
cd DemoTips/
(2)创建Podfile文件,使用命令 pod init,如
pod init
(3)编辑Podfile文件,添加需要使用的第三方库,编辑操作
// 进入文件
vi Podfile
// 进入编辑,点击键盘i进入编辑模式
// 退出编辑,点击键盘Esc退出编辑模式
// 退出文件,点击组合键(Shift + : + w + q)保存退出;或点击组合键(Shift + : + q)不保存退出
// 编辑内容
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'DemoTips' do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
pod 'FMDB', '~> 2.6.2'
pod 'LKDBHelper', '~> 2.1.9'
# Pods for DemoTips
target 'DemoTipsTests' do
inherit! :search_paths
# Pods for testing
end
target 'DemoTipsUITests' do
inherit! :search_paths
# Pods for testing
end
end
(4)安装
// 安装第三方库
$ pod install
// 更新第三方库
$ pod update
// 安装过程的提示信息
zhangshaoyu:DemoTips zhangshaoyu$ pod install
Analyzing dependencies
Downloading dependencies
Installing FMDB (2.6.2)
Installing LKDBHelper (2.1.9)
Generating Pods project
Integrating client project
// 安装成功后的提示信息
[!] Please close any current Xcode sessions and use `DemoTips.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.
(5)使用
安装成功后,会提示项目的使用由原来的xxx. xcodeproj格式变成xxx. xcworkspace格式。
3、创建自己的库
(1)创建xxx.podspec文件,保证与git上创建的repository相同,如
pod spec create SYImageBrowser
(2)编辑xxx.podspec文件
(3)验证,本地文件验证,即进入到xxx.podspec文件所在目录
// 方法1
pod spec lint xxx.podspec
// 方法2 检查修复语法或者逻辑错误
pod spec lint xxx.podspec --verbose
// 方法3 忽略警告
pod spec lint xxx.podspec --allow-warnings
(4)注册了trunk账号
$ pod trunk register [Your-Email] '[Your-Name]' --description='[Your-Desc]'
> [Your-Email]: 任意邮件,但是我比较推荐你使用github上的Email
> [Your-Name]: 推荐使用github上使用的Name
> [Your-Desc]: 一个简单的描述,往往这个时候我们使用的是自己电脑的一个描述
// 比如我自己注册了一个
$ pod trunk register wangcccong@foxmail.com 'ApterKing' --description='wangcong Mac Pro 13'
// 是否注册
pod trunk me
(5)提交到远程仓库
(6)验证,远程仓库文件验证
(7)验证提交
pod search XXX
(8)更新
pod repo update
4、异常处理
(1)cocoapods搜索不到最新的第三库
pod repo update
// 或清除缓存,重新建立索引
pod cache clean --all
rm -rf ~/Library/Caches/CocoaPods
pod repo update
网友评论