將自己的代碼提交到Cocoapods上面以便于自己或其他人使用Cocoapods安裝使用。
一鼎姊,創(chuàng)建倉庫骡和,上傳代碼到碼云(此處以碼云為例)
001
是否開源選擇公開、語言和.gitignore按需選擇相寇、開源許可證必須要有
慰于、選擇MIT,創(chuàng)建倉庫唤衫、上傳代碼
二婆赠,給項目打tag
點擊標(biāo)簽三赃承,注冊CocoaPods賬號
打開終端用命令行注冊cocoapods賬號妙黍,有賬號的話跳過,注冊以后郵箱會收到一封確認(rèn)郵件瞧剖,進(jìn)入郵件中的鏈接完成注冊(使用QQ郵箱注冊時雖然提示我去郵件里驗證拭嫁,但是郵箱一直沒有收到郵件,于是換成了163郵箱)
Last login: Fri Jul 10 11:53:02 on ttys000
//注冊 郵箱抓于、昵稱
twinkleo@TwinkleodeMacBook-Pro ~ % pod trunk register XXXX@163.com 'YourName'
[!] Please verify the session by clicking the link in the verification email that has been sent to XXXX@163.com
//查看自己的注冊信息
twinkleo@TwinkleodeMacBook-Pro ~ % pod trunk me
//如果多人維護(hù)pod 可以添加其他維護(hù)者
twinkleo@TwinkleodeMacBook-Pro ~ % pod trunk add-owner name XXXXX@163.com
- Name: Twinkleo_LZ
- Email: twinkleo_lz@163.com
- Since: July 7th, 02:55
- Pods: None
- Sessions:
- July 10th, 00:08 - November 15th, 00:09. IP:111.222.188.222
四做粤、創(chuàng)建 .podspec文件
Podsepc文件:在所有支持Cocoapods導(dǎo)入的庫的開源目錄(如Github)下,我們都能看到一個.podspec文件捉撮。當(dāng)然我們不管是做公有庫或者是私有庫都是必須配置這個文件的怕品。這個文件是告訴Cocoapods你這個庫的一些基本信息,包括你的版本號呕缭、獲取的地址堵泽、那些文件是希望被包含進(jìn)來的等一些信息修己。
這個文件是在你新建或者需要新提交一個版本的時候回進(jìn)行改動的文件恢总。
.podspec要放在clone到本地的git倉庫的根目錄下面,并提交到倉庫的
終端創(chuàng)建
//cd到文件
twinkleo@TwinkleodeMacBook-Pro ~ % cd /Users/twinkleo/Desktop/XGProgressHUD
//命令行創(chuàng)建 這個名稱就是之后cocoapods搜索使用的名稱睬愤,
//例如AFNetworking片仿、FMDB等
twinkleo@TwinkleodeMacBook-Pro XGProgressHUD % pod spec create XGProgressHUD
//提示創(chuàng)建完成
Specification created at XGProgressHUD.podspec
此時在你的文件夾下面就已經(jīng)生成了podspec五、編輯 .podspec文件
可以用文本編輯工具打開編輯尤辱,也可以用終端打開編輯砂豌。 推薦終端編輯厢岂,用文本編輯工具有可能造成雙引號變成中文導(dǎo)致在之后的驗證中失敗的問題。
終端打開vim XGProgressHUD.podspec
twinkleo@TwinkleodeMacBook-Pro XGProgressHUD % vim XGProgressHUD.podspec
# Not including the public_header_files will make all headers public.
#
spec.source_files = "Classes", "Classes/**/*.{h,m}"
spec.exclude_files = "Classes/Exclude"
# spec.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.
#
# 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
發(fā)現(xiàn)里面有很多阳距,我們使用的其實并不多塔粒,只需要簡單的一些介紹之類的就行,其余的全部可以刪掉筐摘,建議全部刪除重新寫卒茬,.podspec在cocoapods中最終會以json格式展示,這里貼一個MJRefresh的.podspec.json
發(fā)現(xiàn)里面有框架的名稱咖熟、版本圃酵、簡介、框架主頁馍管、開源許可證郭赐、作者信息、最低支持版本确沸、資源文件等
建議直接復(fù)制下面這一部分捌锭,然后更改信息
Pod::Spec.new do |s|
s.name = "XGProgressHUD" # 項目名稱
s.version = "1.0.0" # 版本號 與 你倉庫的 標(biāo)簽號 對應(yīng)
s.license = "MIT" # 開源證書
s.summary = "基于MBProgressHUD的封裝" # 項目簡介
s.homepage = "https://gitee.com/Twinkleo/XGProgressHUD" # 你的主頁
s.source = { :git => "https://gitee.com/Twinkleo/XGProgressHUD.git", :tag => "#{s.version}" }#你的倉庫地址,不能用SSH地址
s.source_files = 'XGProgressHUD/XGProgressHUD.{h,m}'
s.requires_arc = true # 是否啟用ARC
s.platform = :ios, "10.0" #平臺及支持的最低版本
s.frameworks = "UIKit", "Foundation", "CoreGraphics" #支持的框架
# User
s.author = { "Twinkleo" => "1050832257@qq.com" } # 作者信息
end
六罗捎、驗證podspec
//終端驗證
pod lib lint
//或者
pod lib lint --allow-warnings
正確的話會顯示
XGProgressHUD passed validation.
七舀锨、提交發(fā)布
pod trunk push XGProgressHUD.podspec
成功后顯示
--------------------------------------------------------------------------------
?? Congrats
?? XGProgressHUD (1.0.0) successfully published
?? March 7th, 01:39
?? https://cocoapods.org/pods/XGProgressHUD
?? Tell your friends!
八、更新cocoapods宛逗、查詢坎匿、使用
常規(guī)操作
九、更新維護(hù)你的代碼
代碼更新維護(hù)后雷激,就需要重寫發(fā)布替蔬,流程是:
1,重新打標(biāo)簽屎暇、
2承桥,更新XGProgressHUD.podspec中的版本號、
3根悼,pod trunk push XGProgressHUD.podspec 推送到pods倉庫