CocoaPods 系列之一 制作公开库
CocoaPods 系列之二 更新公开库
CocoaPods 系列之三 Podspec 语法说明
CocoaPods 系列之四 Podspec subspec
CocoaPods 系列之五 Private Pods(译文) 制作私有库
CocoaPods 系列之六 Private Pods 制作私有库从0到1
CocoaPods 系列之七 我遇到的验证不过
做私有库前的知识准备:
1 先学会制作公开库,否则白扯
2 会使用git
使用私有库两种方式,第一种有Spec的库,第二种不适用私有的spec库,我们先来看第一种
Private Pods
私有库
CocoaPods is a great tool not only for adding open source code to your project, but also for sharing components across projects. You can use a private Spec Repo to do this.
CocoaPods是一个很好用的工具,不仅能添加公开代码。而且能够制作私有库。
There are a few steps to getting a private pods setup for your project; creating a private repository for them, letting CocoaPods know where to find it and adding the podspecs to the repository.
制作私有库的步骤是:创建私有仓库,把podspec添加到仓库。
1 Create a Private Spec Repo
1 创建私有的Spec Repo
To work with your collection of private pods, we suggest creating your own Spec repo. This should be in a location that is accessible to all who will use the repo.
为了制作私有库,我们建议创建你自己的Spec repo。私有库的权限开放给需要使用库的人。
注解: 例如cocoapods的官方仓库https://github.com/CocoaPods/Specs,把所有的公开库的PodSpec文件放到仓库里,相当于这是一个索引库。
You do not need to fork the CocoaPods/Specs Master repo. Make sure that everyone on your team has access to this repo, but it does not need to be public.
2 Add your Private Repo to your CocoaPods installation
2 添加私有库到你的电脑本地
命令:
$ pod repo add REPO_NAME SOURCE_URL
执行完整个命令后
$ cd ~/.cocoapods/repos/REPO_NAME
$ pod repo lint .
注解:我在码云制作了一个空的仓库,然后执行
pod repo add Haisheng git@gitee.com:haisenv/test_private_library.git
然后:
cd /Users/XXXX/.cocoapods/repos/Haisheng
执行:
pod repo lint .
输出:
All the specs passed validation.
3 Add your Podspec to your repo
3 添加Podspec文件到你的repo库里
Make sure you've tagged and versioned your source appropriately, then run:
确定你已经正确的制作了Podspec文件,然后执行
$ pod repo push REPO_NAME SPEC_NAME.podspec
注解:这里我使用的是测试的公开课,执行了
pod repo push Haisheng HSTestLib.podspec
执行这个步骤后 在我的本地和码云私有库的地址都多了一个东西(原来不只是改变本地,这个命令还把本地的repo推送到了仓库)如下图


That's it!
Your private Pod is ready to be used in a Podfile. You can use the spec repository with the source
directive in your Podfile as shown in the following example:
好了,你的私有库已经准备好在Podfile中使用了。
How to remove a Private Repo
如何移除私有库
pod repo remove [name]
再来看第二种
第一步 把工程写好,代码推送到私有库上
第二步 pod spec create GoGoGo 创建podSpec文件,配置文件,配置后验证通过
- 使用这种方式的时候一定注意库文件和podspec文件一定要放在根目录,默认去根目录寻找到podSpec文件然后去加载文件去
第三步 在Podfile写入
pod 'GoGoGo' , :git => 'git@gitee.com:haisenv/GoGoGoSdk.git',:branch => 'master'
这里不需要添加source。
使用这种方式,更改代码后,更新就好,不需要tag,实用。
第四步
pod install
原理猜测
前提使用git管理代码
一个使用库的指定使用哪个版本,一个库里那么多版本,所以要指定,或者分支或者tag;一个是提供库的。如何把这俩者连接起来,那么podSpec文件就是桥梁,它规定了库的git地址,分享的库文件,依赖文件等等。
网友评论