iOS:CocoaPods制作私有库
2018-10-30 本文已影响9人
lord_95
本章制作私有库方法省去了繁琐的Pod校验,快速简单制作私有库。
创建索引库
我使用的是GitHub
![](https://img.haomeiwen.com/i1573601/81c5fc05630ef7bf.png)
制作Pod
再在GitHub上创建新的工程
![](https://img.haomeiwen.com/i1573601/d6c2c5654a32ace2.png)
把要制作成Pod的文件放入本地git
注意:目录结构、文件夹名称、文件名称,尽量按照截图保持一致。resource文件夹中放入资源文件。(例如.png .xib .bundle .xml 等等)
![](https://img.haomeiwen.com/i1573601/8b231823a9a257a0.png)
重点:podspec编写
编辑ZXYTestPod.podspec
Pod::Spec.new do |s|
#pod名称与上面截图红框中名称保持一致
s.name = 'ZXYTestPod'
#版本号,区分版本,制作索引文件会用到
s.version = '1.0.0'
s.summary = 'WebStartView framework for IOS'
s.description = <<-DESC
test.test
DESC
#git主页
s.homepage = 'https://github.com'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { '904824090@qq.com' => '904824090@qq.com' }
#pod的git地址
s.source = { :git => 'git@github.com:zhangxinyu2018/ZXYTestPod.git', :tag => s.version.to_s }
s.ios.deployment_target = '8.0'
#路径以podspec所在位置为开始
s.source_files = 'ZXYTestPod/*'
s.resources = ['ZXYTestPod/resource/*']
end
podspec的其他属性可以参考官方文档
向索引库中添加索引文件
ZXYTestPod文件夹名称和pod 名称一致(s.name)
1.0.0文件夹名称和pod版本一致(s.version)
把ZXYTestPod.podspec复制到1.0.0文件夹
![](https://img.haomeiwen.com/i1573601/31a67c94d94162fb.png)
把所有文件提交到GitHub
在ZXYTestPod打上tag 1.0.0 (tag值与s.version一致,Version升级时注意所有文件应保持一一致)
把索引库与本地关联
关联命令:$ pod repo add NAME URL [BRANCH]
查看本地已经关联的索引库:pod repo
打开终端
95:~ xxxxx$ pod repo add ZXYSpecs git@github.com:zhangxinyu2018/ZXYSpecs.git
Cloning spec repo `ZXYSpecs` from `git@github.com:zhangxinyu2018/ZXYSpecs.git`
95:~ xxxxx$ pod repo
ZXYSpecs
- Type: git (master)
- URL: git@github.com:zhangxinyu2018/ZXYSpecs.git
- Path: /Users/lord_95/.cocoapods/repos/ZXYSpecs
1 repos
测试
创建测试工程
注意:需要在Podfile中添加 source ‘git@github.com:zhangxinyu2018/ZXYSpecs.git’
source ‘git@github.com:zhangxinyu2018/ZXYSpecs.git’
platform :ios, ‘8.0’
target ‘ZXYPodDemo’ do
pod 'ZXYTestPod'
end
进入到工程所在文件夹执行pod install
95:ZXYPodDemo xxxxx$ pod install
Analyzing dependencies
Downloading dependencies
Installing ZXYTestPod (1.0.0)
Generating Pods project
Integrating client project
[!] Please close any current Xcode sessions and use `ZXYPodDemo.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.
打开ZXYPodDemo.xcworkspace 可以看到制作的pod已经有了。
![](https://img.haomeiwen.com/i1573601/c6b143a3a0cf7414.png)
运行一下,成功!
![](https://img.haomeiwen.com/i1573601/71cee9ddb1f4001f.png)
到这里私有库的制作就完成了。
demo地址:https://github.com/zhangxinyu2018/ZXYPodDemo
索引库ZXYSpecs地址:https://github.com/zhangxinyu2018/ZXYSpecs
pod地址:https://github.com/zhangxinyu2018/ZXYTestPod