注:爲保護個人隱私,本文章中的庫名、郵箱名、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
參考文檔: