1、在GitHub上新建一个仓库,选公开仓库,选MIT的license,新建README.md文件;
2、克隆到本地,把你要上传的库放在仓库文件夹里,这里我用的是界面化git工具sourceTree,当然你也可以用指令
3、用终端cd到你的仓库目录,之后输指令 pod spec create yourSpecName,执行这个指令之后,仓库目录下会多一个yourSpecName.podspec文件
4、还在仓库目录下,用终端输入 vim yourSpecName.podspec,之后按i进行编辑,请按照如下例子进行修改(#开头的语句是被注释掉的语句)
<span style="font-size:14px;">#
# Be sure to run `pod spec lint WYNavigationBarManager.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 = "WYNavigationBarManager"
s.version = "0.0.1"
s.summary = "WYNavigationBarManager is a manager to config your navigationBar gradual change ."
# 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
it is a manager use to change your navigation bar gradualful
DESC
s.homepage = "https://github.com/ivysboy/WYNavigationBarManager"
# 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 = 'MIT'
# 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 = { "Wuyuan" => "359696929@qq.com" }
# Or just: s.author = "Wuyuan"
# s.authors = { "Wuyuan" => "359696929@qq.com" }
# s.social_media_url = "http://twitter.com/徐悟源"
# ――― 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, "7.0"
# s.platform = :ios, "5.0"
# When using multiple platforms
# s.ios.deployment_target = "5.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/ivysboy/WYNavigationBarManager.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 = "WYNavigationBarManager/WYNavigationBarManager/*"
# 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 = "Foundation","UIKit"
# 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
</span>
需要注意的是,在编写podspec文件时,
s.license一定要有,不然无法成功上传到cocoa pods。
还要s.platform = ios : "7.0" 注意对应的iOS版本号。
还有要设置好你希望作为框架的文件的路径s.source_files = ‘WYNavigationBarManager/WYNavigationBarManager/*’,这就表示其他人用pod安装你的框架时,会把你当前仓库目录下,这个WYNavigationBarManager/WYNavigationBarManager/*目录下的所有文件安装到他们的工程中。
还有远程仓库的路径也一定要写好。
5、写完pod spec文件之后,记得推送到你的远程仓库,之后要进行pods验证。
执行如下两条命令:
set the new version to 0.0.1
set the new tag to 0.0.1
上面这两句是为你的pod添加版本号,并打上tag。
然后执行pod验证指令:
pod lib lint
如果一切正常,会出下面的信息
WYNavigationBarManager(0.0.1)
WYNavigationBarManager passed validation
(如果上面这一步执行出现了警告,请用pod lib lint —allow-warnings,就不用管警告了)
之后再推送一下到远程仓库。
6、到这里我们才刚刚准备好可以向cocoapods的github官方仓库推送我们自己的框架
由于在2016年cocoa pods改变了提交机制,我们不能再像以前一样,把cocoapods在github上的spec克隆下来,在里面添加自己的podspec文件了。现在cocoa pods,要求我们以一种新的方式去推送自己的框架。
根据cocoa pods官网上的指引,首先我们要cd到我们已经建好podspec文件的仓库目录下,
输以下指令,之后注册本台电脑到cocoapods,要邮箱验证
pod trunk register yourmail@haha.com ‘your name’ —description=‘your mac name'
点击邮箱的验证连接,会出现
当邮箱验证成功之后,你就可以在这个目录下直接执行
pod trunk push
推送你的podspec文件到cocoa pods的官方仓库了
执行成功之后,你就可以用
pod search yourSpecName
去看一下你的框架了