1.创建私有仓库

coding.netOSChinaGitHub或者自己搭建的Git服务器上创建一个私有仓库,然后在本地添加仓库

1
pod repo add LYSpecs https://git.coding.net/CodingZero/LYSpecs.git

2.创建私有库

创建私有库模板

1
pod lib create VenderName
  • 第一个问题是问你选择Swift还是Objc构建项目。eg: ObjC
1
2
hat language do you want to use?? [ Swift / ObjC ]
> ObjC
  • 第二个问题问你是否需要创建一个Demo项目eg: Yes
1
2
Would you like to include a demo application with your library? [ Yes / No ]
> Yes
  • 第三个问题让你是否选择一个测试框架eg: None
1
2
Which testing frameworks will you use? [ Specta / Kiwi / None ]
> None
  • 第四个问题是否基于View测试eg: No
1
2
Would you like to do view based testing? [ Yes / No ]
> No
  • 第五个问题是询问 类的前缀eg: LY
1
2
What is your class prefix?
> LY

3.更新发布私有库

  • 提交代码
1
git add -A && git commit -m "Release 1.0.0"
  • tag
1
git tag '1.0.0'
  • tag推到远程仓库
1
git push --tags
  • 将本地的master分支推送到远程仓库
1
git push origin master
  • 提交到私有仓库
1
2
3
4
 pod repo push LYSpecs VenderName.podspec --allow-warnings --verbose
// --allow-warnings : 允许 警告,有一些警告是代码自身带的。
// --use-libraries : 私有库、静态库引用的时候加上
// —-verbose : lint显示详情

4.使用私有库

  • 用的时候需要在Podfile里添加源
1
2
3
4
5
6
 // GitHub地址
source 'https://github.com/CocoaPods/Specs.git'
# ...相关库
// 私有库地址
source 'https://git.coding.net/CodingZero/LYSpecs.git'
# ...私有库
  • 用的时候在Podfile里引用
1
pod 'VenderName'
  • 开发模式下测试Pod库的代码
1
pod 'VenderName', :path => '../' # 指定路径

然后在Example工程目录下执行pod update命令安装依赖,打开项目工程,可以看到库文件都被加载到Pods子项目中了
不过它们并没有在Pods目录下,而是跟测试项目一样存在于Development Pods/VenderName 中,这是因为我们是在本地测试,而没有把podspec文件添加到Spec Repo中的缘故。

5.podspec文件配置说明

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#
# Be sure to run `pod lib lint VenderName.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#

Pod::Spec.new do |s|
#名称
s.name = 'VenderName'
#版本号
s.version = '0.1.0'
#简介
s.summary = '这个是我的私有库项目Demo.'

# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!

s.description = <<-DESC
这个是教程的 私有库项目 学习Demo. (主要:比s.summary要长)
DESC
#主页,这里要填写可以访问到的地址,不然验证不通过
s.homepage = 'https://coding.net/CodingZero/VenderName'

# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'

#开源协议

s.license = { :type => 'MIT', :file => 'LICENSE' }

#作者
s.author = { 'DeveloperLY' => 'coderyliu@gmail.com' }

#项目地址,这里不支持ssh的地址,验证不通过,只支持HTTP和HTTPS,最好使用HTTPS。
#这里的s.source须指向存放源代码的链接地址,而不是托管spec文件的repo地址
s.source = { :git => 'https://coding.net/CodingZero/VenderName.git', :tag => "0.1.0" }

#s.social_media_url = 'http://weibo.com/lycoder'

#支持的平台及版本
s.ios.deployment_target = '7.0'

#代码源文件地址,**/*表示Classes目录及其子目录下所有文件,如果有多个目录下则
#用逗号分开,如果需要在项目中分组显示,这里也要做相应的设置

s.source_files = "VenderName/Classes/**/*"

#资源文件地址
# s.resource_bundles = {
# 'MyLib' => ['VenderName/Assets/*.png']
# }

#公开头文件地址
#s.public_header_files = 'VenderName/Classes/**/*.h'

#所需的framework,多个用逗号隔开
s.frameworks = 'UIKit'

#依赖关系,该项目所依赖的其他库,如果有多个需要填写多个s.dependency
# s.dependency 'AFNetworking', '~> 2.3'
end