XCode发布代码到Cocoapod
发布代码到Cocoapod
@(iOS)[CocoaPods]
- 有些公共类,想要放到Cocoapod,这样以后维护起来比较方便。
- 或者自己封装的一些便捷控件都可以发布到Cocoapod。
新建一个工程
-
把需要的封装好的类放到工程中
-
添加demo应用
-
写个小demo,调用一下试试
提交到github
- 拿到github链接
- 这是为了Cocoapod能找到源文件
增加CaptureImagePro.podspec
-
这个文件是给Cocoapod进行索引用的
-
1、添加tag
git tag -a 1.0.0 -m "tag 1.0.0
-
2、push
git push --tags
-
3、创建podspec文件
pod spec create CaptureImagePro
-
4、修改podspec
Pod::Spec.new do |s|
s.name = 'CaptureImagePro'
s.version = '1.0.0'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.homepage = 'https://github.com/slq0378'
s.authors = {'MrSong' => 'slq0378@163.com'}
s.summary = '通过AVFoundation自定义相机,可有效降低内存占用'
s.platform = :ios, '7.0'
s.source = {:git => 'https://github.com/slq0378/CaptureImagePro.git', :tag => s.version}
s.source_files = 'CaptureImagePro/SLQCameraViewController'
s.frameworks = 'AVFoundation'
s.requires_arc = true
end
- 5、验证spec文件有效性
pod spec lint CaptureImagePro.podspec
- 如果有警告,直接
--allow-warnings
忽略
- 如果有警告,直接
song$ pod spec lint CaptureImagePro.podspec
-> CaptureImagePro (1.0.0)
- WARN | xcodebuild: CaptureImagePro/CaptureImagePro/SLQCameraViewController/SLQCameraHelper.m:346:12: warning: incompatible pointer types returning 'CIImage *' from a function with result type 'UIImage *' [-Wincompatible-pointer-types]
Analyzed 1 podspec.
[!] The spec did not pass validation, due to 1 warning (but you can use `--allow-warnings` to ignore it).
trunk 到Cocoapod
-
使用pod trunk命令上传项目至Cocoapods
-
1、注册
pod trunk register xxxxxx@gmail.com 'MrSong' --description='MrSong'
-
2、邮箱里确认就可上传了
pod trunk push CaptureImagePro.podspec
-
3、可通过
pod trunk me
查看自己是否成功 -
4、更新本地库
pod update
-
5、搜索
pod search 'CaptureImagePro'
注意事项
- 如果自己修复了一个bug,那么要对Cocoapod进行更新操作,过程和上面一样,先tag再trunk。最后自己试一下即可。
各种坑
pod spec lint xxx.podsepc
错误
ERROR | [iOS] file patterns: The
source_filespattern did not match any file.
- 这次提交代码一直报错,改了很多次才发现问题。问题在于我的目录结构。
- 这个工程有个子目录(UIImage),但是我一直是包含一个目录(Categories),这样就找不到子目录
- 前只包含一个目录
s.source_files = 'SLQCategories/Categories/*.{h,m}'
一直报上面那个错误, 找不到子目录。 - 后两个目录
s.source_files = 'SLQCategories/Categories/*.{h,m}','SLQCategories/Categories/**/*.{h,m}'
分开来写,分别包含
- 前只包含一个目录
pod下来的目录不对
- 实际需要pod下来的文件目录为了和原先的目录保持一直,我原先以为会和实际目录一直,但是实际情况却相反,所有的文件全部在一个根目录下面。
- pod 下来是这样
- podspec文件如下
Pod::Spec.new do |s|
s.name = 'SLQCategories'
s.version = '1.0.4'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.homepage = 'https://github.com/slq0378'
s.authors = {'MrSong' => 'xxxx.com'}
s.summary = 'iOS分类集合,各种简单易用分类'
s.platform = :ios, '7.0'
s.source = {:git => 'https://github.com/slq0378/SLQCategories.git', :tag => s.version}
s.source_files = 'SLQCategories/Categories/*.{h,m}','SLQCategories/Categories/UIImage/*.{h,m}'
s.frameworks = 'AVFoundation'
s.requires_arc = true
end
-
实际上我是希望把真是目录显示出来,这样查看比较方便,这里参考AFNetworking的做法。
-
-
podspec文件如下
Pod::Spec.new do |s|
s.name = 'SLQCategories'
s.version = '1.0.4'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.homepage = 'https://github.com/slq0378'
s.authors = {'MrSong' => 'xxx@.com'}
s.summary = 'iOS分类集合,各种简单易用分类'
s.platform = :ios, '7.0'
s.source = {:git => 'https://github.com/slq0378/SLQCategories.git', :tag => s.version}
s.source_files = 'SLQCategories/Categories/*.{h,m}'
# s.source_files = 'SLQCategories/Categories/*.{h,m}','SLQCategories/Categories/UIImage/*.{h,m}'
s.frameworks = 'AVFoundation'
s.requires_arc = true
# 子目录
s.subspec 'UIImage' do |ss|
ss.source_files = 'SLQCategories/Categories/UIImage/*.{h,m}'
end
end
本文来自博客园,作者:struggle_time,转载请注明原文链接:https://www.cnblogs.com/songliquan/p/12784446.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
2015-06-04 IOS开发学习笔记041-UITableView总结1
2015-06-04 ios开发学习笔记040-autolayout 第三方框架Masonry