如何建立自己的公有pod

如果在開發(fā)過程中,想把自己封裝的一些控件、分類打包以pod的形式供自己或團隊使用,我們可以建立公有pod或者私有pod。

以下指示介紹如何打包公有pod供自己使用。

步驟 1.
前往githup建立庫。

cocoapods.png

選擇MIT 認證(得到cocopods的認證許可。)

接下來把你需要的上傳的工具類放到目錄下:


目錄.png

步驟二:

創(chuàng)建.podspec文件。
LXUtils 是你新建庫的名字。

pod spec create LXUtils

執(zhí)行完上面的命令,會生成一個.podspec的文件。

可以編輯打開,我是通過webStorm打開的(不知道為什么,通過默認的編輯器打開后面進行spec文件驗證的時候經(jīng)常提示語法錯誤,所以建議還是通過工具打開吧):

最好還是根據(jù)里面的修改。切記tag選項前面必須添加v

s.name         = "LXUtils"
 s.version      = "0.0.1"
 s.summary      = "common tools on iOS."
s.description  = <<-DESC
                common tool and category on iOS
                   DESC
  s.homepage     = "https://github.com/liuxinixn/LXUtils"
s.license      = "MIT"
 s.author             = { "miss李" => "missli_211@163.com" }
s.platform     = :ios, "8.0"

s.source       = { :git => "https://github.com/liuxinixn/LXUtils.git", :tag => "v#{s.version}" }

s.source_files  = "LXUtils", "LXUtils/**/*.{h,m}"
s.framework  = "UIKit"
  s.requires_arc = true

修改好對應的選項之后,驗證spec文件的合法性。

pod lib lint LXUtils.podspec
驗證.png

步驟3.

綁定tag,然后發(fā)布。

git tag '0.0.1'  
git push --tags  
git push origin master

下面的命令需要你去郵箱進行驗證

pod trunk register jiushu0228@163.com 'LXUtils'
pod trunk me

驗證結果


郵箱驗證.png

如果出現(xiàn)下面的問題:

[!] The spec did not pass validation, due to 1 error.
[!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 2.3, run: 
    `echo "2.3" > .swift-version`.

執(zhí)行echo "2.3" > .swift-version即可。

最后一步,發(fā)布spec到cocoapods

pod trunk push LXUtils.podspec

成功后如下:

zhongzhideMini:LXUtils chenergou$ pod trunk push LXUtils.podspec
Updating spec repo `master`

CocoaPods 1.3.0.beta.3 is available.
To update use: `sudo gem install cocoapods --pre`
[!] This is a test version we'd love you to try.

For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.3.0.beta.3

Validating podspec
 -> LXUtils (0.0.1)

Updating spec repo `master`

CocoaPods 1.3.0.beta.3 is available.
To update use: `sudo gem install cocoapods --pre`
[!] This is a test version we'd love you to try.

For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.3.0.beta.3


--------------------------------------------------------------------------------
 ??  Congrats

 ??  LXUtils (0.0.1) successfully published
 ??  November 8th, 02:45
 ??  https://cocoapods.org/pods/LXUtils
 ??  Tell your friends!

補充

提交后需要等一段時間,如果搜不到試試下面的方法:
根據(jù)路徑~/Library/Caches/CocoaPods/search_index.json找到這個json文件,然后刪除即可。

重新'pod search LXUtils'

輸出:Creating search index for spec repo 'master'.. Done!,稍等片刻就會出現(xiàn)所有帶RxSwift字段的類庫出現(xiàn)。

如何更新pod

1.升級版本

git tag 'v0.0.2'  
git push --tags  
git push origin master

2.更新到cocoapods

pod trunk push LXUtils.podspec

成功之后,如果搜索不到執(zhí)行pod setup

總結

主要命令:

git tag 0.0.1   //打tag
git push --tags //推送tag到遠程
git push origin master 
pod lib lint//驗證spec文件的合法型
pod trunk push LXMUtils.podspec //推送spec

pod trunk register xxx@163.com 'userName' --verbose //每次注冊新的倉庫必須驗證一次
pod trunk me//驗證結果
git tag -d 0.0.1 //移除某個tag
git push origin :refs/tags/0.0.1 //遠程移除某個tag

推薦文章 :http://www.cocoachina.com/articles/25864

最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容