【iOS】上传开源框架到CocoaPods

2019-10-13  本文已影响0人  irenb

1.提交代码到GitHub,并打上框架版本标签

// 提交本地代码
git add .
git commit -m "提交框架代码"
// 打上标签
git tag 2.2.0
git push --tags
// 推送master分支的代码到远程仓库
git push origin master

其它命令:

git tag -d 2.2.0
git push origin -d tag 2.2.0

2.创建.podspec描述文件

上传到cocoapods时主要就依赖着.podspec的描述文件来进行配置的,所以我们要先建立一个.podspec的描述文件:

pod spec create BRPickerView
Pod::Spec.new do |s|
  # 框架的名称
  s.name         = "BRPickerView"
  # 框架的版本号
  s.version      = "2.3.4"
  # 框架的简单介绍
  s.summary      = "A custom picker view for iOS."
  # 框架的详细描述(详细介绍,要比简介长)
  s.description  = <<-DESC
                    A custom picker view for iOS, Include "日期选择器,时间选择器,地址选择器,自定义字符串选择器,支持自定义样式,适配深色模式", Support the Objective - C language.
                DESC
  # 框架的主页
  s.homepage     = "https://github.com/91renb/BRPickerView"
  # 证书类型
  s.license      = { :type => "MIT", :file => "LICENSE" }

  # 作者
  s.author             = { "任波" => "ios@91renb.com" }
  # 社交网址
  s.social_media_url = 'http://blog.91renb.com'
  
  # 框架支持的平台和版本
  s.platform     = :ios, "8.0"

  # GitHub下载地址和版本
  s.source       = { :git => "https://github.com/91renb/BRPickerView.git", :tag => s.version.to_s }


  s.public_header_files = 'BRPickerView/BRPickerView.h'
    
  # 本地框架源文件的位置(包含所有文件)
  # s.source_files  = "BRPickerView/**/*.{h,m}"
  
  # ------------- iOS中Pod库中使用podspec配置层级目录 ------------- 
  # 一级目录(pod库中根目录所含文件)
  s.source_files  = "BRPickerView/BRPickerView.h"

  # 二级目录(根目录是s,使用s.subspec设置子目录,这里设置子目录为ss)
  s.subspec 'Base' do |ss|
    ss.source_files = 'BRPickerView/Base/*.{h,m}'
  end
  
  s.subspec 'DatePickerView' do |ss|
    ss.dependency 'BRPickerView/Base'
    ss.source_files = 'BRPickerView/DatePickerView/*.{h,m}'
  end
  
  s.subspec 'AddressPickerView' do |ss|
    ss.dependency 'BRPickerView/Base'
    ss.source_files = 'BRPickerView/AddressPickerView/*.{h,m}'
  end
  
  s.subspec 'StringPickerView' do |ss|
    ss.dependency 'BRPickerView/Base'
    ss.source_files = 'BRPickerView/StringPickerView/*.{h,m}'
  end
  # ------------------------------------------------------------

  # 框架包含的资源包
  s.resources  = "BRPickerView/AddressPickerView/BRPickerView.bundle"

  # 框架要求ARC环境下使用
  s.requires_arc = true

end

pod spec lint BRPickerView.podspec --allow-warnings

3.注册CocoaPods

pod trunk register borenfocus@gmail.com 'renbo' --description='任波的CocoaPods账号'

成功的话就会受到一份邮件,点击邮件中的链接后验证一下

pod trunk me

成功的话会返回以下类似字段:

- Name:     renbo
- Email:    borenfocus@gmail.com
- Since:    August 11th, 2017 03:48
- Pods:
  - BRPickerView
  - BRNetwork
- Sessions:
  - August 11th, 2017 03:48 - September 3rd, 2018 01:50. IP:
  132.198.20.124  Description: macbook pro
  - October 13th, 05:28     - February 18th, 2020 05:30. IP:
  125.120.215.202 Description: 任波的CocoaPods账号

如果你的pod是由多人维护的,你也可以添加其他维护者:

pod trunk add-owner ARAnalytics kyle@cocoapods.org

4. 提交到CocoaPods

pod trunk push BRPickerView.podspec --allow-warnings

上传成功会提示如下一些信息:

--------------------------------------------------------------------------------
 🎉  Congrats

 🚀  BRPickerView (2.3.0) successfully published
 📅  October 13th, 05:52
 🌎  https://cocoapods.org/pods/BRPickerView
 👍  Tell your friends!
--------------------------------------------------------------------------------
pod search BRPickerView

框架信息:

-> BRPickerView (2.2.1)
   A custom picker view for iOS.
   pod 'BRPickerView', '~> 2.2.1'
   - Homepage: https://github.com/91renb/BRPickerView
   - Source:   https://github.com/91renb/BRPickerView.git
   - Versions: 2.2.1, 2.2.0, 2.1.3, 2.1.2, 2.1.1, 2.1.0, 2.0.0, 1.3.0, 1.2.0,
   1.1.0, 1.0.0 [master repo]

如果查不到当前上传的最新版本,就 pod repo update 更新一下本地 CocoaPods 库

其它命令:

pod trunk delete BRPickerView 2.3.0

以上是第一次上传的操作,后续更新框架操作如下:

上一篇下一篇

猜你喜欢

热点阅读