14.创建属于自己的远程私有组件库
1.代码托管平台创建spec的私有库
这里我使用的是coding, 网址是: https://coding.net.
1.1 创建一个spec的索引私有库, 填写相关信息


1.2最后点击创建项目.
2.本地生成公钥秘钥
2.1电脑选择, 前往->个人->.ssh文件
2.2查看发现, 只有一个known_hosts文件
2.3打开cmd, 输入
ssh-keygen
2.4然后会提示
// 成功生成本地公钥秘钥
Generating public/private rsa key pair.
// 以下三个选项可以输入enter设置
Enter file in which to save the key (xxxx):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
2.5再次查看, 前往->个人->.ssh文件

3.在代码托管平台绑定公钥
3.1在个人设置中,选择SSH公钥

3.2新增公钥

3.3将步骤2本地生成的公钥( id_rsa.pub文件 ), 用xcode打开拷贝到下面指定位置, 点击添加

3.4输入密码后, 会显示添加成功
4.在本地添加spec的私有索引库
4.1 查看本地所有的索引库
打开cmd, 输入
pod repo
会显示pod的公有库master

4.2 添加自己的远程私有索引库
打开cmd, 输入
// XXX是myPrivateSpecBase的SSH地址, 在托管仓库中拷贝地址
pod repo add myPrivateSpecBase XXX
4.3检查是否添加本地私有索引库成功
打开cmd, 输入
pod repo
你会发现, 除了master外, 多了一个私有的索引库
4.4 移除索引库,可以输入
pod repo remove myPrivateSpecBase
至此, 本地私有spec索引库已经添加成功
5.在代码托管平台, 创建远程代码托管仓库, 步骤和上面的步骤1相同

6.创建本地组件库
6.1在本地创建远程仓库文件夹, 然后打开cmd, 定位到该文件夹
6.2在cmd输入pod lib create MyComponents , 创建本地模板库
pod lib create MyComponents
填写以下模板信息

6.2再次查看6.1生成的文件夹, 会显示




本地组件代码编译成功后, 准备提交到托管平台前,一定要修改spec文件信息, tag 和进行spec的合理性测试.
s.source 的地址一定要使用https的, 不能使用SSH的地址

6.4 定位到组件库, 检测spec是否填写正确
cd /Users/xxx/Desktop/xcode工程/ZGKFMBase_respec/remoteLib/MyComponents
// 检查spec是否填写正确
pod spec lint

上述报错, 是没有给组件打上tag
解决方法:上传代码 + 打上tag
git status
git add .
git commit -m '修改'
// 查看是否有绑定仓库
git remote
// 添加仓库 myOrigin(第一次添加,需要添加仓库)
git remote add myOrigin https://git.xxxxxxx/MyComponents.git
// 推送代码
git push myOrigin master
//
描述:向github仓库推送时(git push origin master),出现如下错误:
error: 无法推送一些引用到 'https://github.com/yourname/youname.github.io.git'
提示:更新被拒绝,因为远程版本库包含您本地尚不存在的提交。这通常是因为另外
提示:一个版本库已向该引用进行了推送。再次推送前,您可能需要先整合远程变更
提示:(如 'git pull ...')。
提示:详见 'git push -- help' 中的 'Note about fast-forwards' 小节。
解决方案:
git push -u origin +master
强行更新。具体为什么,没研究。
// git强行更新
git push -u origin +master
6.5上传代码到远程仓库后, 需要打标签
// 查看已有版本标签
git tag
// 打标签0.2.0
git tag '0.2.0'
// 推送tag
git push --tags
// 如果上面的不行,则使用下面的( git push + 仓库 + --tags )
git push myOrigin master --tags
//
6.6至此,本地组件库已经创建成功, 并推送到远程托管平台
7.将spec推送到自己私有的索引库
7.1 对同级目录下的spec文件进行合理性检测
pod spec lint
以下是检测成功:

7.2 , 将spec推送到自己私有的索引库(spec被推送到私有索引库后, 会向上推向到pod的远程索引库)
// 查看本地索引库
pod repo
// 将spec推送到自己私有的索引库
pod repo push myPrivateSpecBase MyComponents.podspec
下面就是已经推送成功的提示:

推送成功后, 会自动更新本地私有索引库
7.3 查看本地私有库是否添加spec成功
路径: (用户 -> .cocoapods -> ..... )

7.4 查看远程私有库是否添加spec成功


7.5 pod search 查找(完美)

8. 项目中使用pod, 将私有组件加入
8.1 在安装私有库的组件时,要指定源source, 否则安装不成功

pod install 后报错

所以, 要在cmd, 输入pod repo, 找到分别的源地址source, 指定优先安装私有索引库指定的组件
一定要设置私有和公有的source, 如果只设置私有库source, 公有库的AFNetWorking就安装不了了.


// 查看本地索引库, 可以从中查找到源source
pod repo
至此, 已经完成了自己的远程私有组件库.
9. 重点总结
// 9.1 本地生成公钥秘钥
ssh-keygen
// 9.2本地添加自己的远程私有索引库
// XXX是myPrivateSpecBase的SSH地址, 在托管仓库中拷贝地址
pod repo add myPrivateSpecBase XXX
// 9.3在cmd输入pod lib create MyComponents , 创建本地模板库
pod lib create MyComponents
// 9.4git强行更新
git push -u origin +master
// 9.5推送tag,则使用下面的( git push + 仓库 + --tags )
git push myOrigin master --tags
// 9.6spec合理性检查
pod spec lint
// 9.7将spec推送到自己私有的索引库
pod repo push myPrivateSpecBase MyComponents.podspec