pods 私有库分为代码库和索引仓库,私有库主要是配置索引文件,添加到podspec文件到pods索引库中。
首先同步git repo 仓库
pod repo add demo www.gitee.demo:jj/xx.git
新建私有仓库
pod lib create demo
查看repo列表
pod repo list
修改podspec 文件,注意summary,desc,git source 地址
Pod::Spec.new do |s|
s.name = 'ZZNTT'
s.version = '0.1.1'
s.summary = '描述文件'
# 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
DESC
s.homepage = 'https://gitee.com/izhongnan/ZZNTT'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'ZZN' => 'dream_at@live.cn' }
s.source = { :git => 'https://gitee.com/izhongnan/ZZNTT.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.ios.deployment_target = '8.0'
s.requires_arc = true
s.frameworks = 'UIKit'
s.source_files = 'ZZNTT/Classes/**/*'
s.module_name = 'DlOemMoudle'
# s.resource_bundles = {
# 'ZZNTT' => ['ZZNTT/Assets/*.png']
# }
# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
# s.dependency 'AFNetworking', '~> 2.3'
end
commit 本地私有仓库,加入tag
git add -A
git commit -s -m "Initial Commit of Library"
git remote add origin XXX.git
git push origin master
git tag 0.1.0
git push --tags
验证文件
pod lib lint
pod lib lint --no-clean 查看错误详情
pod lib lint --allow-warnings 允许警告(包括xcode编译的warning)
向Spec Repo提交podspec
pod repo push demo(本地repo) demo.podspec
使用
pod 'demo', :git => 'www.gitee.demo:jj/xx.git'
注意问题
1, swift库注意 SWIFT_VERSION 和 module_name
2, pod spec lint 可以添加--allow-warnings
3, storyboard,xib等资源文件可以打包成bundle后,通过s.resource_bundles引用
4, 库中引用资源等,需要找到当前文件所在的bundle来引用
let moudleFileBundle = Bundle.init(for: self.classForCoder())
let img = UIImage.init(named: name, in: moudleFileBundle, compatibleWith: nil)
参考官方文档