如何提交代码至 CocoaPods?这个问题在 Google 一搜索可以有很多文章出来,不过,其中遇到的坑却无人提及。笔者现在将实际操作工程记录如下,并总结踩坑注意事项:操作顺序、文件配置、命令使用。
准备工作
提交代码
将需要提交至 CocoaPods 的代码提交至代码托管服务器,例如:GitHub。
这里需要注意的是,提交的代码需要包含 tag
标签。其实就是 git 里面的 git tag
。
安装或更新 CocoaPods
安装
$ gem install cocoapods
更新
$ pod update
注册 Trunk
$ pod trunk register e_mail_address 'your_name'
注意:记得去注册邮箱激活
查看注册信息
$ pod trunk me
- Name: charsdavy
- Email: chars.davy@gmail.com
- Since: July 15th, 21:38
- Pods:
- JCCNavigationController
- Sessions:
- July 15th, 21:38 - November 21st, 01:45. IP: xx.xx.xx.xx
创建 .podspec 文件
.podspec
文件的作用是为了让 CocoaPods 搜索引擎知道该代码的作者、版本号、概要、描述、源代码地址、部署版本、依赖的框架等描述信息。
.podspec
文件可以自动生成:
$ pod spec create JCCNavigationController // 生成 JCCNavigationController.podspec 文件
JCCNavigationController.podspec
文件内容:
#
# Be sure to run `pod spec lint JCCNavigationController.podspec' to ensure this is a
# valid spec and to remove all comments including this before submitting the spec.
#
# To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
#
Pod::Spec.new do |s|
# ――― 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.
#
s.name = "JCCNavigationController"
s.version = "1.0"
s.summary = "A navigation bar integrated transition animation effect."
# 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
With zoom interactive animation, A navigation bar integrated transition animation effect.
DESC
s.homepage = "https://github.com/charsdavy/JCCNavigationController"
s.screenshots = "https://raw.githubusercontent.com/charsdavy/JCCNavigationController/master/Screenshot.gif"
# s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"
# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Licensing your code is important. See http://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'.
#
s.license = { :type => "MIT", :file => "LICENSE" }
# s.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.
#
s.author = { "charsdavy" => "charsdavy@gamil.com" }
s.social_media_url = "https://twitter.com/charsdavy"
s.swift_version = "4.0"
# ――― 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.
#
s.platform = :ios
s.platform = :ios, "8.0"
# When using multiple platforms
s.ios.deployment_target = "8.0"
# s.osx.deployment_target = "10.7"
# s.watchos.deployment_target = "2.0"
# s.tvos.deployment_target = "9.0"
# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Specify the location from where the source should be retrieved.
# Supports git, hg, bzr, svn and HTTP.
#
s.source = { :git => "https://github.com/charsdavy/JCCNavigationController.git", :tag => "#{s.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.
#
s.source_files = "JCCNavigationController/*.swift"
# s.exclude_files = "Classes/Exclude"
# s.public_header_files = "Classes/**/*.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.
#
# s.resource = "icon.png"
# s.resources = "Resources/*.png"
# s.preserve_paths = "FilesToSave", "MoreFilesToSave"
# ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Link your library with frameworks, or libraries. Libraries do not include
# the lib prefix of their name.
#
# s.framework = "SomeFramework"
# s.frameworks = "SomeFramework", "AnotherFramework"
# s.library = "iconv"
# s.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.
# s.requires_arc = true
# s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
# s.dependency "JSONKit", "~> 1.4"
end
以上文件,需要注意 s.platform
这个字段,文本中的注释说的很明白,默认是全平台都支持的,如果只支持某一个平台,则需要细心配置完善。
验证 .podspec
文件是否合法
$ pod spec lint JCCNavigationController.podspec
如果配置文件仍存在错误,则根据错误提示修复错误。
如果只有以下一个错误,则只需提交代码即可:
ERROR | unknown: Encountered an unknown error (uninitialized constant REST::DisconnectedError) during validation.
提交 .podspec
文件
将 .podspec
文件提交至代码托管服务器,例如,将 JCCNavigationController.podspec
文件提交至 JCCNavigationController
项目。
提交代码至 CocoaPods
$ pod trunk push JCCNavigationController.podspec --allow-warnings
返回以下信息则为成功:
--------------------------------------------------------------------------------
🎉 Congrats
🚀 JCCNavigationController (1.0) successfully published
📅 July 16th, 00:58
🌎 https://cocoapods.org/pods/JCCNavigationController
👍 Tell your friends!
--------------------------------------------------------------------------------
附录
JCCNavigationController
JCCNavigationController,一种导航栏一体化转场动画效果。
DDCornerRadius
DDCornerRadius,优化圆角实现方案,避免离屏渲染。