由于github的私有库需要收费,因此我们使用码云(gitee)的私有库,免费。
1、创建WJSpec远程私有仓库,用来存放podspec文件。
1.1 在码云中创建私有项目:


1.2 添加你的私有Repo到你的CocoaPods
pod repo add WJSpec https://gitee.com/winjayq/WJSpec.git


1.3 如果需要删除,则使用终端命令:
pod repo remove WJSpec
2、创建WJCategory远程仓库,用来存放项目工程文件

2.1 创建pod私有仓库的模板
pod lib create WJCategory

执行完会自动打开工程:

2.2 代码拖到classes
将代码拖到ReplaceMe.m的文件目录下,删除ReplaceMe.m

2.3 pod安装进行测试
cd 到Example目录

安装成功

在Example工程里引入头文件就可以使用了

2.4 修改podspec描述文件

2.5 自己本地端检测 pod lib lint
修改完成后,cd 到WJCategory目录下,然后验证podspec文件
pod lib lint
出现WJCategory passed validation.则验证通过。
2.6 提交项目到远程仓库
cd 到WJCategory目录下
git add .
git commit -m '分类组件'
关联远程仓库,提交:

push到远程的时候出现这种问题,于是就先pull ,于是就出现了图中这种经典的问题了

重新输入如下命令:
git pull origin master --allow-unrelated-histories

解决一下冲突就可以了。解决冲突后上传到远程仓库。
解决冲突参考链接:https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/001375840202368c74be33fbd884e71b570f2cc3c0d1dcf000
手动修改冲突的文件:

提交到远程,这样远程仓库就有我们本地的项目了:
git push origin master

2.7 pod spec lint 远程端检测
注意:如果私有库中依赖私有库,则验证podspec文件的时候需要加上–sources参数,否则会出现找不到你依赖的私有库。
远程端检测报错:

显示我们没有远程仓库打标签,这里需要重点注意的是,我们给打的标签值要与podspec文件中的版本号一致。

再次使用pod spec lint,成功:

2.9 向私有的spec Repo远程仓库中提交podspec
使用 pod repo push yourRepoName yourPodName.podspec 命令把私有库添加到私有repo中
注意的是:仍然在本项目的目录路径下进行操作:

前往文件夹 ~/.cocoapods/repos去查看WJSpec目录下的文件如下:

远程WJSpec仓库与本地WJSpec仓库是同步的:

然后使用 pod search 'WJCategory' 就可以搜索出来了。

到此,创建私有库算创建成功了。
2.10 使用自己创建的私有pod库
使用source 指定路径
source 'https://gitee.com/winjayq/WJSpec.git' #个人私有仓库
source 'https://github.com/CocoaPods/Specs.git' #github仓库


网友评论