cocoapod 私有库制作

私有库制作

参考 https://guides.cocoapods.org/syntax/podspec.html

创建pod库

$ cd 合适的目录(最好是空文件夹)
$ pod lib create test_sh(库名字)

这一步会提示你输入一些参数,如是否包含测试Demo、那种语言、类名前缀、姓名、邮箱等,然后生成test_sh.podspec和一些工程文件。就制作pod库而言,有些参数是无关紧要的(但却是pod lib create命令必须要输入的),所以熟练后,可以直接手动生成xxxx.podspec,自行添加需要的文件。

一个简短的podspec示例

# 校验本文件,使用 `pod lib lint test_sh.podspec'
# 详细语法 https://guides.cocoapods.org/syntax/podspec.html

Pod::Spec.new do |s|
  s.name             = 'test_sh' #库名字
  s.version          = '0.1.0'  #版本号 遵循semantic versioning
  s.summary          = '简短摘要'

  s.description      = <<-DESC
                   一些介绍
                       DESC

  s.homepage         = 'https://xxx.yyy.zzz/test_sh' #主页
  s.license          = { :type => 'MIT', :file => 'LICENSE' }  #法律协议
  s.author           = { 'zxs.zl' => '[email protected]' } #作者和联系方式
  s.source           = { :git => 'https://abc.efg/test_sh.git', :tag => s.version.to_s } #仓库地址

  s.ios.deployment_target = '8.0' #ios版本

  s.source_files = 'test_sh/Classes/**/*'  #参与编译的文件  **表示递归查找

  #资源文件
  # s.resource_bundles = {
  #   'test_sh' => ['test_sh/Assets/*.png']
  # }

  # s.public_header_files = 'Pod/Classes/**/*.h'  #需要公开的头文件
  # s.frameworks = 'UIKit', 'MapKit'  #依赖的ios系统库
  # s.dependency 'AFNetworking', '~> 2.3'  #依赖的三方库
  # s.vendored_libraries = 'test_sh/Classes/*.a'   #lpod库含有lib库时使用
  # s.vendored_frameworks = 'test_sh/Classes/*.framework'  # pod库含有framework库时使用
end

上传文件

test_sh.podspec和工程文件一同上传到test_sh.podspec中描述的仓库上,本文示例的仓库为https://abc.efg/test_sh.git(当然这并不存在)

可以将podspec和工程文件分别上传到不同仓库,这里不考虑,仅仅是演示。

并打上tag (和test_sh.podspecs.version 的保持一致)
本文示例的tag为0.1.0

一个简单的私有pod制作完成

引用私有库

私有库的引用和公有库没有太大区别,只是需要指定库的地址
简短podfile示例

 platform :ios, '8.0'
 inhibit_all_warnings!  # 忽略引入库的所有警告
 target '你的target' do
   pod 'test_sh', :git =>'https://abc.efg/test_sh.git', :tag =>'0.0.1'
end

猜你喜欢

转载自blog.csdn.net/holdsky/article/details/86520080
今日推荐