在开发过程中,经常会使用到第三框架,我们通过一个pod install命令,很方便的就将第三方框架加到我们自己的项目中。
如果我们也想将自己写的组件或库开源出去,让别人也可以通过pod install命令安装自己的框架该怎么做呢?下面,我就教大家一步一步的将自己的pods发布到CocoaPods 中。如果你现在对CocoaPods还不太了解,推荐你看一看这篇文章:用CocoaPods做iOS程序的依赖管理
近期研究CocoPods的制作,本文章为记录其制作过程以及本人所遇到的问题,以及解决方法。本文章记录本人制作的过程,如有可以修正之处,欢迎留言指教。
制作过程参考:
主要过程如下:
一、创建自己的git仓库
二、clone仓库到本地
三、向本地git仓库中添加创建Pods依赖库所需文件
四、提交修改文件到github
五、上传podspec文件到CocoaPods官方仓库中
六、查看我们自己创建的Pods依赖库
七、删除提交到cocoapods上的框架
篇章较长,本次介绍制作过程遇到问题以及解决办法,全部篇章如下:
问题以及解决办法如下:
在执行pod spec lint PodName.podspec 命令时候遇到报错
也许有些地方是多余的,也贴出来给大家参考。
1.缺乏证书,新建的GitHub仓库没有选择许可证。没法,只能删了重新建(参考本文步骤一)
2.没有打tag(我也出现同样问题,暂时使用以下的示例说明发布CocoaPods组件碰到的坑与心得体会 )
Validating podspec
-> XLPhotoBrowser (1.0.0)
- ERROR | [iOS] unknown: Encountered an unknown error ([!] /Applications/Xcode.app/Contents/Developer/usr/bin/git clone https://github.com/xiaoL0204/XLPhotoBrowser.git /var/folders/w1/95fypdq96l92t55frcn0yhyh0000gn/T/d20161206-1790-put1kd --template= --single-branch --depth 1 --branch 1.0.0
Cloning into '/var/folders/w1/95fypdq96l92t55frcn0yhyh0000gn/T/d20161206-1790-put1kd'...
warning: Could not find remote branch 1.0.0 to clone.
fatal: Remote branch 1.0.0 not found in upstream origin
) during validation.
[!] The spec did not pass validation, due to 1 error.
解决方式:
我是在git上面还有SourceTree上面都打了Tag,保持一致
3.swift版本不对
[!] The validator for Swift projects uses Swift 2.3 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 3.0, run:
`echo "3.0" > .swift-version`.
或者
[!] The spec did not pass validation, due to 1 errorand 1 warning.[!] The validator for Swift projects uses Swift 3.0by default, if you are using a different version of swift you can use a`.swift-version` file to set the version for your Pod. For example to use Swift2.3, run: `echo "2.3" > .swift-version`.
解决:
echo "3.0" > .swift-version cd到对应文件夹路径下执行该命令
或 echo"2.3" > .swift-version
4.podspec文件配置不对。
4.1.
- ERROR | File Patterns: File patterns must be relative and cannot start with a slash (source_files).
解决
检查 s.source_files 对应文件地址是否正确
4.2. 有别的说法是 s.description需要这样写(我也照做了),如下
s.description = <<-DESC
这里写你的描述内容
DESC
不能写为
s.description = <<-DESC这里写你的描述内容DESC
5. description is shorter 短于 summary.
- WARN | description: The description is shorter than the summary.
- ERROR | [iOS] unknown: Encountered an unknown error (/usr/bin/xcrun
simctl list -j devices
解决:
修改 .podspec文件,把description编辑内容多于summary
6. 找不到Xcode
xcode-select: note: no developer tools were found at
'/Applications/Xcode.app', requesting install. Choose an option in the dialog
to download the command line developer tools.
) during validation.
原因:由于我的Xcode没放在Applications中造成的错误
解决:将Xcode工具拖到Applications 并确保它的名字为Xcode.app(有时候有beta版本的Xcode,记得改文件名)
7.CocoaPods Updating
Updating spec repo `master`
[!] CocoaPods was not able to update the `master`
repo. If this is an unexpected issue and persists you can inspect it running
`pod repo update --verbose`
解决:
终端执行 pod repo update --verbose
8.cocopods加载xib文件显示不出来
我提交的代码有: XX.h 、XX.m 、 XX.xib;通过项目podfile获取的文件都有下来,其中.xib是在Resources里面
但是运行程序,不能加载到.xib文件
这是由于bundle没找到;于是在XX.m文件中,viewDidLoad方法重新加载XX.xib文件,代码如下(同时兼容git的代码):
NSString *Bundle_Name =@"XX.bundle";
NSString *Bundle_Path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:Bundle_Name];
NSBundle* Bundle = [NSBundlebundleWithPath:Bundle_Path];
if(Bundle)
{
self.view = [Bundle loadNibNamed:@"XX" owner:self options:nil].lastObject;
}
暂时是以上的内容,后续如果有其他问题,我继续补充。