0%

私有pod库创建

创建私有pod库:

创建公有Pod库或者私有Pod库, 实际上原理是一样的, 都是基于git服务和repo协议, 不一样的是, 两者的版本索引查询方式不一样, 公有库的podspec由CocoaPods/Specs管理, 而内部私有使用的pod库需要自己建立一个仓库来管理podspec.

1
2
3
// 创建pod库
// 例如:pod lib create GJNotifyView
pod lib create [repo-name]

回车之后,终端会询问你几个哲学的问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 选择编程语言
What language do you want to use?? [ Swift / ObjC ]
> Objc

# 在你的项目中是否创建一个demo工程,为了方便测试,我选择了Yes
Would you like to include a demo application with your library? [ Yes / No ]
> Yes

# 测试框架选择哪一个
Which testing frameworks will you use? [ Specta / Kiwi / None ]
> None

# 要不要做视图测试
Would you like to do view based testing? [ Yes / No ]
> Yes

# 类前缀名
What is your class prefix?
> GJ

pod项目安装

1
2
// 安装CocoaPods项目
pod install --no-repo-update
  • 将项目添加到库的Classes文件夹中

编辑CocoaPods的配置文件(后缀名为podspec)

编辑CocoaPods的配置文件

pod项目更新

1
2
// 更新CocoaPods项目
pod update --no-repo-update

验证pod配置文件

1
2
// 验证pod配置文件
pod lib lint

发布项目

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 添加远程地址,即上面创建码云项目的地址
BetterdeMacBook-Pro:PrivateHelloWorld better$ git remote add origin https://gitee.com/Better_Y/PrintHelloWorld.git
# 添加文件
BetterdeMacBook-Pro:PrivateHelloWorld better$ git add .
# 提交本地,并写描述
BetterdeMacBook-Pro:PrivateHelloWorld better$ git commit -a -m "第一次提交 版本为0.0.1"
# --allow-unrelated-histories
# git pull origin maste会失败 ,提示:fatal: refusing to merge unrelated histories
# 原因是远程仓库origin上的分支master和本地分支master被Git认为是不同的仓库,所以不能直接合并,需要添加 --allow-unrelated-histories

BetterdeMacBook-Pro:PrivateHelloWorld better$ git pull origin master --allow-unrelated-histories
# 推送到码云的PrintHelloWolrd项目的master分支上
BetterdeMacBook-Pro:PrivateHelloWorld better$ git push origin master
# 提交版本号
BetterdeMacBook-Pro:PrivateHelloWorld better$ git tag 0.0.1
# push到远程分支
BetterdeMacBook-Pro:PrivateHelloWorld better$ git push origin 0.0.1

创建并发布Sepc管理库

1
2
3
4
5
6
// 创建Sepc
pod repo add [repo-name] [git-url]
// 发布
pod repo push [repo-name] [name.podspec]
// 删除
pod repo remove [repo-name]

使用Cocoapods私有库

  • 指定其他工程的Podfile文件中source字段为私有仓库repo仓库地址
    1
    pod 'repo-name', :source=>'cocoapods-repo-url'
-------------本文结束感谢您的阅读-------------