cocoaPods 私有仓库的创建和使用

cocoaPods 私有仓库的创建和使用

一、创建远程的POD 仓库

直接在git上创建一个空的pod仓库即可,

执行

pod repo add #仓库名字# 仓库地址

自动会将远程私有仓库clone到 /Users/用户名/.cocoapods/repos 目录下。

自此 远程仓库已经准备好了。

二、创建本地的组件

使用命令

pod lib create [pod name]

会自动创建一个本地的库,我们可以在这里开发我们的组件库。

这里最主要的是NAME.podspec 这个文件的配置 类似如下

#
# Be sure to run `pod lib lint AUExtension.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html
#

Pod::Spec.new do |s|
  s.name             = 'Extension'
  s.version          = '0.1.9' # 版本号,这个版本号一定要和tag号一致,需要先打tag,
  s.summary          = 'A short description of AUExtension.'

# 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
TODO: Add long description of the pod here.
                       DESC

  s.homepage         = 'http://gitlab..net'
  # s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { 'ericdream' => '595814260@qq.com' }
  s.source           = { :git => '你的代码仓库地址', :tag => s.version.to_s }
  # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

  s.ios.deployment_target = '8.0'

  s.source_files = 'Extension/Classes/Extension.h'
  
  s.subspec 'MiscExtend' do |ss|
      ss.source_files = 'Extension/Classes/MiscExtend/**/*.{h,m}'
  end
  
  s.subspec 'Extend' do |ss|
      ss.source_files = 'Extension/Classes/UIExtend/**/*.{h,m}'
      ss.dependency 'Extension/MiscExtend'
      mrcFiles = 'Extension/Classes/UIExtend/**/UIViewController+ExchageDeallocFunction.{h,m}'
      ss.exclude_files = mrcFiles
      ss.subspec 'MRC' do |sp|
          sp.source_files = mrcFiles
          sp.requires_arc = false
      end
      
  end
  
  
  # s.resource_bundles = {
  #   'Extension' => ['Extension/Assets/*.png']
  # }

  # s.public_header_files = 'Pod/Classes/**/*.h'
  # s.frameworks = 'UIKit', 'MapKit'
  # s.dependency 'AFNetworking', '~> 2.3'
end

version: 组件的版本号,必须和tag 号保持一致

source_files :资源的路径,

exclude_fies : 忽略的资源文件,不包含

requires_arc : 是否开启arc 默认开启arc

public_header_files :头文件

frameworks: 需要的frameworks

libraries :所有的libraries,注意:需要去掉前缀 lib,如:s.libraries=‘z.1.2.5’ (依赖库:libz.1.2.5)

dependency: 需要的依赖

特别注意,cocoapod中没有文件目录的概念,只有子组件的概念,如果没有子组件,所有的文件都在同一级目录下,要’分目录’就要建立子组件。每一个子组件就是一个目录。子组件之间相互依赖调用的时候需要依赖被调用的组件。

配置文件修改完成之后,可以提交代码到远端,并打一个tag,tag和 配置文件中的s.version 保持一致。

三、验证并把cocoaPods 配置文件推送到远端仓库

配置文件写完成之后我们需要验证配置文件的正确性。那么如何验证呢。

通过命令:pod lib lint name.podspec --use-libraries --allow-warnings --verbose 后边参数可以去掉,建议加上,第一个参数不加可能不会通过验证,不忽略警公告也不会验证通过,

验证通过之后我们就可以把配置文件推送的pod远端仓库:

pod repo push 仓库名 配置文件.podspec --sources='自己仓库地址,https://github.com/CocoaPods/Specs.git' --use-libraries --allow-warnings --verbose

如果你的组件不依赖私有组件可以去电自己的pod私有仓库地址。

执行这条命令之后,系统会自动的在 /Users/用户名/.cocoapods/repos 目录下 创建一个和版本号同名的目录,并把配置文件copy进来,然后在另外的一个目录下创建工作空间,并编译你的组件,编译通过之后才真正的把配置文件提交到pod仓库。

自此pod 库完成制作。

四、使用

要使用我们自己自作的私有仓库首先你需要在 profile 文件中添加上你的仓库源地址:

如:source 'http://gitlab........respos.git'

然后再添加仓库:

pod '组件名'

pod 版本共控制

  • pod ‘组件’, ‘1.0’ # 指定版本

  • ‘> 0.1’ 0.1 以上

  • ‘>= 0.1’ 大于等于 0.1

  • ‘< 0.1’ 小于0.1

  • ‘<= 0.1’ 小于等于0.1

  • ‘~> 0.1.2’ # 0.1 以上,0.2 一下

  • ‘~>0.1’ # 0.1以上 1.0 一下

最后只需要执行命令:

pod install

完成。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值