一、更新维护podspec
1、更新podspec版本
我们在上一篇介绍了如何如何创建使用私有podspec
,现在来说一下制作好的podspec
后续的更新维护工作,比如添加新的版本,依赖第三方库等...
我们看下我更新了TestTool
项目之后的目录结构:
我在新版本中工具里边添加了CommentImageView
这个类,他继承与UIView
,里边用SDDWebImage
加载了一张图片,我们要做的是发布TestTool_pod
的0.0.2
版本,此版本里边有新的图片类,及第三方的引用.
***deMini:TestTool ***$ git tag 0.0.2
***deMini:TestTool ***$ git tag
0.0.1
0.0.2
***deMini:TestTool ***$ git push origin 0.0.2
我们可以在Git服务器上看到0.0.2
版本,此时我们继续修改podspec
文件:
Pod::Spec.new do |s|
s.name = "TestTool_pod"
s.version = "0.0.2"
s.summary = "测试pod使用TestTool_pod工具库0.0.2b版本"
s.description = <<-DESC
TestTool中包含Person类,请在项目中通过pod导入TestTool工具,并使用Person类
TestTool中添加了CommentImageView类
DESC
s.homepage = "https://coding.net/u/***/p/TestTool"
s.license = { :type => "MIT", :file => "LICENSE" }
s.author = { "***" => "***@qq.com" }
s.source = { :git => "https://***:***@git.coding.net/***/TestTool.git", :tag => "#{s.version}" }
s.source_files = "TestTool/Tool", "TestTool/Tool/**/*.{h,m}"
s.dependency 'SDWebImage', '~> 4.3.3'
end
然后我们验证文件pod lib lint
,此时控制台提示信息:
-> TestTool_pod (0.0.2)
- ERROR | [OSX] unknown: Encountered an unknown error (CocoaPods could not find compatible versions for pod "SDWebImage":
In Podfile:
TestTool_pod (from `/Users/wangbaoxiang/Desktop/TestTool`) was resolved to 0.0.2, which depends on
SDWebImage (~> 4.3.3)
Specs satisfying the `SDWebImage (~> 4.3.3)` dependency were found, but they required a higher minimum deployment target.) during validation.
[!] TestTool_pod did not pass validation, due to 1 error.
You can use the `--no-clean` option to inspect any issue.
从提示信息中SDWebImage (~> 4.3.3) dependency were found, but they required a higher minimum deployment target.) during validation
我们可以看到第三方库找到了,但是他要求有一个最低的开发环境,我们查阅SDWebImage资料可以看到,4.3.3
版本的SDWebImage
要求iOS 7.0 or later。
于是我们在podspec
文件中添加:
s.platform = :ios, '9.0'
然后继续pod lib lint
:
-> TestTool_pod (0.0.2)
TestTool_pod passed validation.
这个时候我们可以看到已经验证通过了,然后再次提交到Spec Repo
,命令:
$ pod repo push TestTool_pod TestTool_pod.podspec
这时候报错:
Validating spec
Cloning spec repo `-1` from ``
[!] Unable to add a source with url `` named `-1`.
You can try adding it manually in `~/.cocoapods/repos` or via `pod repo add`.
此错误尚未解决,这里直接手动操作:
前往~/.cocoapods/repos
,手动添加0.0.2
版本按照0.0.1版本的目录结构
然后执行pod search
命令:
已经可以看到两个版本的搜索结果。
2、使用新版本
私有库已经更新至新版本,那么我们可以在测试项目testPod
中测试新版本是否可用:
修改Podfile
文件
pod 'TestTool_pod', '~> 0.0.2'
然后执行pod install
命令,这个时候控制台输出:
Analyzing dependencies
[!] CocoaPods could not find compatible versions for pod "TestTool_pod":
In Podfile:
TestTool_pod (~> 0.0.2)
None of your spec sources contain a spec satisfying the dependency: `TestTool_pod (~> 0.0.2)`.
You have either:
* out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
* mistyped the name or version.
* not added the source repo that hosts the Podspec to your Podfile.
Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by default.
因为在第一步最后我们是手动导入的0.0.2
版本,此时索引可能缺失,我们执行pod repo update
命令,更新完毕之后,继续执行pod install
:
Analyzing dependencies
Downloading dependencies
Installing SDWebImage (4.3.3)
Installing TestTool_pod 0.0.2 (was 0.0.1)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 2 total pods installed.
安装成功,此时我们可以看到testPod
项目目录结构:
不但有我们新的工具类CommentImageView
,连第三方SDWebImage
也替我们下载好了。
运行测试代码:
3、删除Spec Repo
如何删除一个私有的Spec Repo
,只需要一行命令:
$ pod repo remove TestTool_pod
删除之后,我们还可以重新添加回来
$ pod repo add TestTool_po https://git.coding.net/***/TestTool.git