1.创建远程索引库和私有库
在Git上创建一个XSpecs的私有索引库,用来索引以后创建的组件模块。
2.将远程索引库添加到本地
查看本地的索引库
pod repo
如果没有安装过私有仓库,应该只有一个共有索引库
master
Type: git (master)
URL: https://github.com/CocoaPods/Specs.git
Path: /Users/*/.cocoapods/repos/master
添加刚刚创建的索引,把索引库clone到本地,然后添加索引地址到本地。
cd /Users/......
git clone https://gitee.com/......
// pod repo add 索引库名称 索引库地址
pod repo add XSpecs https://gitee......
可以使用’pod repo’查看是否添加成功,如果添加成功,会显示你的索引库名称和地址。
3.在本地创建一个pod模板库
在Git上创建一个组件的仓库。
快速创建模板库
cd到合适的地方,使用命令
// pod lib create 组件名
pod lib create XDPhoto
会让选择一些配置,根据自己的情况自行选择。
把ReplaceMe.m文件删除,替换成自己的组件代码。Classes文件夹中的文件,是pod install时要下载下来的文件。如果里面有两个文件夹,pod install后文件自动也会分文件显示。
修改Spec文件,主要是源这一项要正确,地址一定是自己组件的远方仓库地址,其他可以根据自己项目情况配置。
s.source = { :git => 'https://gitee.com/.....git', :tag => s.version.to_s }
4.上传代码和打标签
上传组件的代码
上传代码前可以先本地检测一下,检测通过后再进行代码上传和tag操作。
pod spec lint
$ git add .
$ git commit -m "init"
git remote add origin https://gitee.com/xiaodev/XDPhoto.git
git push -f origin master//第一次加上-f
//git push origin master
打上和spec文件中s.version一致的tag
git tag '0.1.0'
git push --tags
5.提交spec至私有索引库
本地检测,本地验证不会验证 s.source 中的tag。私有仓库的验证要加上–private,不然会有警告,也可以加上–allow-warnings忽略警告。
pod lib lint --private
远程验证,会验证s.source 中的tag。
pod spec lint --private
提交podspec到索引仓库。
// pod repo push 私有索引库名称 spec名称.podspec
pod repo push XSpecs SD**.podspec
成功后可以尝试搜索一下组件。
pod search 'SD**'
如果search不到,可以删除~/Library/Caches/CocoaPods/中的search_index.json文件,重新pod saerch。
6.使用
添加组件到项目的Podfile中。
文件顶部添加描述
// 第二行是为了保证公有库的正常使用
source 'https://gitee.com/x***/XSpecs.git'
source 'https://github.com/CocoaPods/Specs.git'
然后添加组件
pod 'SD**'
安装组件
pod install