iOS私有库制作(一)
一、创建一个空的私有库项目gitHub地址,用于存放私有库项目。gitHub 下创建一个空的repository,这里起名SBAIPractice,不勾选README.md 等。

创建后:

2.创建私有库 SBAIPractice,到自己的想要放pod项目的目录下,执行如下命令创建私有库:
pod lib create SBAIPractice
依次回答如下问题:
最后一个为你的项目类名前缀


3.关联第一步中创建的空git
由于pod lib创建pod工程时默认已经准备了LICENSE、README.md、.gitignore三个文件,若在github上创建新建空白项目pod时勾选了这三个文件,则git pull时会产生冲突。解决方式:将pod工程目录下与github项目冲突的文件删除。
此外,pod项目目录下默认准备了.git仓库,关联时不用重新git init。
cd到pod项目目录下

执行:
git add .
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/Manchitor/SBAIPractice.git
git push -u origin main
git push 有时会报错超时,多试几次。

第一步创建的空项目刷新会看到已经关联成功了

二、配置Pods工程的.podspec文件。主要是s.version、s.summary、s.source的编辑。
SBAIPractice.podspec的内容如下:

s.name :pod search 搜索的关键词,注意这里一定要和.podspec的名称一样
s.version :版本号,每一个版本对应一个tag
s.summary : 简介
s.homepage : 项目主页地址
s.license : 许可证
s.author : 作者
s.social_media_url : 社交网址
s.source : 项目的地址
s.source_files : 需要包含的源文件
s.resources: 资源文件
s.requires_arc : 是否支持ARC
s.dependency :依赖库
s.ios.deployment_target = ‘10.0' : 支持的pod最低版本
s.source_files = ‘pod_test/Classes//’,这里表示匹配所有子目录,表示匹配所有文件。
修改后SBAIPractice.podspec后,cd到Example文件夹下执行pod install。检查是否设置正确。
代码更新后先关闭workspace,一定要执行:pod install 来更新,更新完需要重新打开workspace。
1.打标签,推送到远程。重点:tag打的版本号必须和podspec中的s.version值相同
CocoaPods进行仓库版本管理时,就是通过.podspec文件中s.version的值到git远程仓库上找与之相同的tag标签的版本。
这里将s.version改为: s.version = ‘1.0.0'
git add .
git commit -m '设置podspec文件为1.0.0'
git push -u origin main
git tag 1.0.0
git push —tags
查看所有tag内容:git tag -l -n

gitHub中效果为:

2.验证.podspec文件的格式是否正确,必须打完tag才能验证,且必须验证,否则后面执行pod repo push或pod trunk push一定失败。
cd到SBAIPractice目录,执行命令
//--allow-warnings:加上该选项,验证时如果有警告会忽略警告,否则无法验证通过
//--use-libraries:如果依赖了静态库就需要加上该选项
pod spec lint --allow-warnings --use-libraries
或
pod lib lint pod_test.podspec --allow-warnings --use-libraries
//如果失败,报超时,可多试几次

三、将本地的podspec文件推送到远程索引库中。
1.创建一个空的git仓库用于存放podSpec。如第一步。这里起名为SBAIPracticeSpec。git地址为:https://github.com/Manchitor/SBAIPracticeSpec.git
2.本地创建一个存放podspec的目录,可随意。本文这里与SBAIPractice同级别。

3.本地目录关联git,cd到SBAIPracticeSpec下后一次执行如下命令,注意替换git地址。
git add .
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/Manchitor/SBAIPracticeSpec.git
git push -u origin main
4.创建本地索引
pod repo add SBAIPracticeSpec https://github.com/Manchitor/SBAIPracticeSpec.git
那么在路径~/.cocoapods/repos下就会有SBAIPracticeSpec本地仓库。

5.将索引push到远程索引仓库
到SBAIPractice.podspec所在的目录下。
pod repo push SBAIPracticeSpec SBAIPractice.podspec --allow-warnings --use-libraries
push成功会打印"Adding the spec to the `mySpecs’ repo”。

之后mySpecs本地仓库里面多了pod_test库的索引(也就是pod_test.podspec),同时会push同步到https://github.com/Manchitor/SBAIPracticeSpec.git
如下图

回到本地目录SBAIPracticeSpec 下。pull一下。

本地目录如下图:

6.试试效果
pod search ’SBAIPractice’
出现如下图:

到现在已经完成,
四、试试
随便找一个工程,修改podfile

终端执行pod install

回到项目会发现 已经引入了。

注:下一章,讲述为私有库添加第三方及创建代码文件。