发布公有库到cocopods

注:为保护个人隐私,本文章中的库名、邮箱名、git地址相关的地址都已经切换成非真实的,但流程是我一步一步走过的真实可靠。

1.GitHub创建共有库.

2.克隆代码到本地。

git clone https://github.com/demo/CYKFoundations.git

3.cd  CYKFoundations, 在克隆的项目中建SourceCode和demo两个文件夹,其中SourceCode中放源码,demo中新建一个xcode项目。

4.添加tag并提交github master分支。

git add -A && git commit -m "Release 1.0.0"

git tag '1.0.0'

git push --tags

git push origin master

5.创建podspec文件。

pod spec create CYKFoundations.podspec

之后在该目录下会生成一个 CYKFoundations.podspec 文件,打开并编辑这个文件,填写好配置文件。

Pod::Spec.new do |spec|

 

  # ―――  Spec Metadata  ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

  #

  #  These will help people to find your library, and whilst it

  #  can feel like a chore to fill in it's definitely to your advantage. The

  #  summary should be tweet-length, and the description more in depth.

  #

 

  spec.name         = "CYKFoundations"

  spec.version      = "1.0.4"

  spec.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!

  spec.description  = <<-DESC

常用方法,类别的封装

                   DESC

 

  spec.homepage     = "https://github.com/CYKFoundations"

  # spec.screenshots  = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"

 

 

  # ―――  Spec License  ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

  #

  #  Licensing your code is important. See https://choosealicense.com for more info.

  #  CocoaPods will detect a license file if there is a named LICENSE*

  #  Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.

  #

 

#  spec.license      = "MIT (example)"

   spec.license      = { :type => "MIT", :file => "FILE_LICENSE" }

 

 

  # ――― Author Metadata  ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

  #

  #  Specify the authors of the library, with email addresses. Email addresses

  #  of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also

#  accepts just a name if you'd rather not provide an email address.

  #

  #  Specify a social_media_url where others can refer to, for example a twitter

  #  profile URL.

  #

 

  spec.author             = { "Jerry" => "*********@163.com" }

  # Or just: spec.author    = "Jerry"

  # spec.authors            = { "Jerry" => ""*********@163.com" }

  # spec.social_media_url   = "https://twitter.com/Jerry"

 

  # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

  #

  #  If this Pod runs only on iOS or OS X, then specify the platform and

  #  the deployment target. You can optionally include the target after the platform.

  #

 

   spec.platform     = :ios

   spec.platform     = :ios, "8.0"

 

  #  When using multiple platforms

  # spec.ios.deployment_target = "5.0"

  # spec.osx.deployment_target = "10.7"

  # spec.watchos.deployment_target = "2.0"

  # spec.tvos.deployment_target = "9.0"

 

 

  # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

  #

  #  Specify the location from where the source should be retrieved.

  #  Supports git, hg, bzr, svn and HTTP.

  #

 

  spec.source       = { :git => "https://github.com/CYKFoundations.git", :tag => "#{spec.version}" }

 

 

  # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

  #

  #  CocoaPods is smart about how it includes source code. For source files

  #  giving a folder will include any swift, h, m, mm, c & cpp files.

  #  For header files it will include any header in the folder.

  #  Not including the public_header_files will make all headers public.

  #

 

  spec.source_files  = "SourceCode/**/*.{h,m}"

# spec.exclude_files = "Classes/Exclude"

 

 

   spec.public_header_files = "SourceCode/**/*.h"

 

 

  # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

  #

  #  A list of resources included with the Pod. These are copied into the

  #  target bundle with a build phase script. Anything else will be cleaned.

  #  You can preserve files from being cleaned, please don't preserve

  #  non-essential files like tests, examples and documentation.

  #

 

  # spec.resource  = "icon.png"

  # spec.resources = "Resources/*.png"

 

  # spec.preserve_paths = "FilesToSave", "MoreFilesToSave"

 

 

  # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

  #

  #  Link your library with frameworks, or libraries. Libraries do not include

  #  the lib prefix of their name.

  #

 

  # spec.framework  = "SomeFramework"

  # spec.frameworks = "SomeFramework", "AnotherFramework"

 

  # spec.library   = "iconv"

  # spec.libraries = "iconv", "xml2"

 

 

  # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

  #

  #  If your library depends on compiler flags you can set them in the xcconfig hash

  #  where they will only apply to your library. If you depend on other Podspecs

  #  you can include multiple dependencies to ensure it works.

 

   spec.requires_arc = true

 

  # spec.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }

  # spec.dependency "JSONKit", "~> 1.4"

 

end

podspec介绍:

#  基本信息的配置
name:框架名
version:当前版本(注意,是当前版本,假如你后续更新了新版本,需要修改此处)
summary:简要描述,在pod search的时候会显示该信息。
description:详细描述
homepage:页面链接
license:开源协议
author:作者
platform:支持最低ios版本
swift_version : swift对应的版本


# 源文件的配置
source:源码git地址
source_files:源文件(可以包含.h和.m)
subspec:子库
public_header_files:头文件(.h文件)
resource_bundles:资源文件(配置的文件会放到你自己指定的bundle中)

# 依赖的配置
frameworks:依赖的系统框架
vendored_frameworks:依赖的非系统框架
libraries:依赖的系统库
vendored_libraries:依赖的非系统的静态库
dependency:依赖的三方库

6.验证podspec文件

pod spec lint CYKFoundations.podspec 

如果因为警告不通过加--allow-warnings

pod spec lint CYKFoundations.podspec --allow-warnings

7.注册cocopods

查看自己是否注册过Trunk

pod trunk me

如果没有注册过请注册

// 加上--verbose可以输出详细debug信息,方便出错时查看。

pod trunk register zhangsan@163.com "zhangsan" --verbose

"zhangsan" 里面代表你的用户名,最好起一个好的名字

zhangsan@163.com 代表你的邮箱

注册完成之后会给你的邮箱发个邮件,进入邮箱邮件里面有个链接,需要点击确认一下

注册成功后可以再查看一下个人信息pod trunk me

8.上传到cocoapods

pod trunk push CYKFoundations.podspec 

如果因为警告不通过加--allow-warnings

pod trunk push CYKFoundations.podspec  --allow-warnings

如果上传成功会出现下面的提示

?  Congrats

 

?  CYKFoundations (1.0.4) successfully published

?  February 19th, 08:51

?  https://cocoapods.org/pods/CYKFoundations

?  Tell your friends!

 

9.pod 搜索你自己的库

pod search CYKFoundations

这里可能会出搜索不到的情况,原因是cocoapods本地库里面没有包含你的这个库需要更新本地库。

pod setup更新我们本地的CocoaPods space库,如果还是不可以,清理下搜索缓存:rm ~/Library/Caches/CocoaPods/search_index.json,清理完再搜索就可以了。

搜索成功的结果是

-> CYKFoundations (1.0.4)

   常用基础封装

   pod 'CYKFoundations', '~> 1.0.4'

   - Homepage: https://github.com/CYKFoundations

   - Source:   https://github.com/CYKFoundations.git

   - Versions: 1.0.4, 1.0.3, 1.0.2 [master repo]

(END)

 

参考文档:https://www.cnblogs.com/gwca/p/8194951.html

参考文档:https://www.jianshu.com/p/bd9a680e0653

参考文档:

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值