iOS制作私有pod仓库
昨天试了一下制作私有pod仓库,被网上各种教程搞得死去活来,在参考了几篇文章,折腾了整整一个下午后,终于把整个流程搞清楚了,想着既然如此就干脆写篇文章记录一下吧。
先把步骤简要说明一下:
制作私有pod库
1.创建私有pod仓库(需要一个git仓库)
2.创建代码库(需要另一个git)
3.将代码库添加到仓库中
4.更新代码库版本
不少教程把第一步和第二步的git混淆了,搞得我不要不要的/(ㄒoㄒ)/~~,本文git都是直接使用github,其他git工具也是一样。好了话不多说,开始吧。
创建私有pod仓库
1.首先在github上新建一个仓库,由于是教程,我就不使用Private了。

2.接着创建完成后,把仓库clone地址复制一下。

3.打开本地终端,输入命令创建pod仓库
pod repo add PrivatePods https://github.com/YakirLove/PrivatePods.git
其中的git地址便是上一步复制的地址,结果如图所示

再看一下本地pod仓库中多了一个PrivatePods文件夹。(LocalPod是我之前添加的, 无视它)

ok,至此我们的本地私有仓库已经创建完成
创建代码库
1.使用终端,先cd到我们要存放代码库的文件夹下,运行命令,创建一个PodTest
pod lib create PodTest
结果如图所示

创建过程中有几个问题需要选择
1.使用什么语言
2.是否需要一个例子工程
3.选择一个测试框架
4.是否基于View测试
5.类的前缀
根据自己情况选择即可,完成后会自动打开一个xcode工程

其中PodTest.podspec就是这个代码库的pod描述文件,而代码库的代码文件则会显示在Pods > Development Pods > PodTest下。
2.在代码库中添加代码
PodTest > PodTest > Classes 存放的就是我们的代码,我们把ReplaceMe.m删掉,加入2个代码文件。


3.用终端cd到Example文件夹下,运行pod install看看文件能否被正常pod

运行完成后,xcode工程的结构如下,表示pod正常

4.在github上新建一个repository,命名成PodTest

将我们本地的PodTest工程git add到这个repository上

再打个0.0.1的tag上去
5.修改podspec文件,这个网上教程一大堆,就不说了,结果如下
Pod::Spec.new do |s|
s.name = 'PodTest'
s.version = '0.0.1'
s.summary = 'PodTest'
s.description = <<-DESC
测试工程 PodTest
DESC
s.homepage = 'https://github.com/YakirLove/PodTest'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'wuyanji' => '282335315@qq.com' }
s.source = { :git => 'https://github.com/YakirLove/PodTest.git', :tag => '0.0.1' }
s.ios.deployment_target = '8.0'
s.source_files = 'PodTest/Classes/**/*'
end
最后cd到这个podspec文件目录下,运行命令
pod lib lint
如果出现下面这个状态就表示配置是正确的,接下来只要把这个文件添加到我们的仓库中就可以了

在仓库中添加代码库
在终端中接着输入
pod repo push PrivatePods PodTest.podspec
运行成功后,你会看到下面这个

注意
如果这里出现一个错误提示
The repo `PrivatePods` at `../.cocoapods/repos/PrivatePods` is not clean
记得要运行下
pod repo update PrivatePods
如果这样还不行,可能是你有在这个文件夹下做过操作,会有一些隐藏文件.Dstore之类,删掉再重新运行即可。
现在我们就可以新建一个项目,pod试一下
source 'https://github.com/YakirLove/LocalPod.git'
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
target 'TestP' do
pod 'AFNetworking', '~> 3.1.0'
pod 'PodTest', '~> 0.0.1'
end
注意这里的source,要加上公有的git才能pod一些公有的第三方库
运行一下
pod install
结果如下,说明我们的代码库PodTest已经制作成功

更新代码库版本
1.首先我在PodTest > PodTest > Classes中加入2个文件,如下

2.在把代码提交之前可以先在PodTest > Example目录下运行一下pod install 看下结果

可以正常编译通过,那就可以了
3.接着将这两个文件提交到github上,并打上tag=0.0.3

4.然后修改一下podspec文件,修改后结果如下
Pod::Spec.new do |s|
s.name = 'PodTest'
s.version = '0.0.3'
s.summary = 'PodTest'
s.description = <<-DESC
测试工程 PodTest
DESC
s.homepage = 'https://github.com/YakirLove/PodTest'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'wuyanji' => '282335315@qq.com' }
s.source = { :git => 'https://github.com/YakirLove/PodTest.git', :tag => '0.0.3' }
s.ios.deployment_target = '8.0'
s.source_files = 'PodTest/Classes/**/*'
end
5.接着把文件推送到repo中,cd到podspec文件目录下,运行
pod repo push PrivatePods PodTest.podspec

6.最后在测试工程TestP中pod install一下,即可看到最新的文件了

参考文章:
1.http://blog.wtlucky.com/blog/2015/02/26/create-private-podspec/
2.http://wonderdevboy.com/2017/03/10/CocoaPods%E7%A7%81%E6%9C%89%E4%BB%93%E5%BA%93%E7%9A%84%E5%88%9B%E5%BB%BA/