CocoaPods是目前比较流行的依赖库管理工具,基本的介绍、安装和使用可以参考这篇文章, 讲得非常详细, 这里就不重复造轮子了。本文主要说说如何通过CocoaPods管理自己在GitHub或者SVN上的私有库。
一.创建podspec文件
在终端cd到工程根目录,然后执行如下命令
1
| pod spec create LibraryName
|
之后会生成一个LibraryName.podspec的文件,这是一个默认生成的,注释写的特别详细,花几分钟看一看基本上就知道各个参数的意思了。然后把里面的东西对号入座换成自个的,基本上就能用了。下面是我在GitHub上的一个测试用例
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
| Pod::Spec.new do |s|
s.name = "TestView"
s.version = "0.0.1"
s.summary = "测试一下TestView."
s.description = <<-DESC
A longer description of TestView in Markdown format.
测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试
DESC
s.homepage = "http://www.baidu.com"
s.license = "MIT"
s.author = { "GJ" => "devwgj@gmail.com" }
s.platform = :ios, "7.0"
#git
s.source = { :git => "https://github.com/devgj/TestView.git", :tag => s.version.to_s }
#svn
#s.source = { :svn => "http://192.168.1.1/svn/repo/TestView", :tag => s.version.to_s }
#TestModel, 在Pod生成的主目录下创建名为Model的文件夹,里面放上以TestM的开头的.h和.m文件
s.subspec 'Model' do |model|
model.source_files = 'TestView/TestM*.{h,m}'
model.frameworks = 'AVFoundation'
end
#TestView
s.subspec 'View' do |view|
view.source_files = 'TestView/TestV*.{h,m}'
view.dependency 'TestView/Model'
end
#资源文件,图片啥的。
s.resources = "TestView/TestView.bundle"
s.requires_arc = true
#依赖SDWebImage,如果你之前的Pod里面没有SDWebImage,
#则会自动下载一个,如果有了,就不会再下载。
s.dependency "SDWebImage"
end
end
|
二、使用CocoaPods管理自己的私有库
在Podfile文件中加上自己私有库的地址就OK了,很方便。
1
2
3
4
5
6
7
8
9
10
| platform :ios, '7.0'
target 'PodTest' do
pod "TestView", :git => "git@github.com:devgj/TestCocoaPods.git"
#pod 'TestView', :svn => 'http://192.168.1.1/svn/repo/TestView'
end
target 'PodTestTests' do
end
|
最后pod install
或者pod update
一下就OK了