經(jīng)過長時(shí)間的開發(fā),學(xué)習(xí)和沉淀,都會有一些自己好用的封裝的庫,但是每次都導(dǎo)入代碼過于麻煩,所以我們可以創(chuàng)建我們自己的 pod 庫,再用起來就會方便很多。下面就是小白創(chuàng)建和上傳的步驟和上傳中可能出現(xiàn)的問題解決方法。
首先創(chuàng)建自己的 trunk 賬號
pod trunk me
查看是否有 trunk 賬號,如圖1,說明有賬號

如果查不到信息,說明沒有賬號,需要注冊賬號
pod trunk register 203***82@qq.com 'HJ'
[!] Please verify the session by clicking the link in the verification email that has been sent to 203***82@qq.com
登錄郵箱去驗(yàn)證
203***82@qq 郵箱是 GitHub 賬號 或者 碼云 賬號 'HJ' 是作者名稱,當(dāng)你上傳成功 pod 庫時(shí)顯示的名稱
創(chuàng)建項(xiàng)目上傳到 GitHub 或 碼云
項(xiàng)目的創(chuàng)建就不在這里描述了,上傳項(xiàng)目以上傳GitHub為例
打開 GitHub ,并登錄賬號。
創(chuàng)建項(xiàng)目



3.準(zhǔn)備上傳項(xiàng)目,首先在本地創(chuàng)建一個文件夾,用來和 github 關(guān)聯(lián),文件夾隨意命名。

4.打開終端,切入路徑到剛剛創(chuàng)建的文件夾中

5.開始使用
Git命令,首先初始化Git環(huán)境
git init

6.關(guān)聯(lián)Git 庫,使用剛剛創(chuàng)建的Git項(xiàng)目地址
git clone https://github.com/***/HJBaseTableView.git
然后就拉取到了項(xiàng)目的空文件夾,切換到空文件夾,然后把創(chuàng)建的項(xiàng)目內(nèi)容拉進(jìn)來


7.上傳代碼文件
git add . // 添加所有改動文件
git commit -m '提交操作的描述' // 添加改動描述
git push // 推送到GitHub
創(chuàng)建 podspec 文件
常用的語句
Pod::Spec.new do |spec|
spec.name = "HJBaseTableView" // 庫名稱
spec.version = "0.0.1" // 庫版本
spec.summary = "Modules and components framework for iOS." // 庫描述
spec.authors = { 'HJ' => '203***82@qq.com' } // trunk 賬號 郵箱 (作者 : 郵箱)
spec.description = <<-DESC
一個簡單的TableView 內(nèi)部采用了 FDTemplateLayoutCell 計(jì)算和緩存高度,方便創(chuàng)建和使用。
DESC // 庫的詳細(xì)描述
spec.homepage = "https://github.com/***/HJBaseTableView" // 庫的Git地址主頁
spec.license = { :type => "MIT", :file => "LICENSE" } // 固定的 版權(quán)校驗(yàn)
spec.platform = :ios, "9.0" // 支持的最低版本 iOS
spec.source = { :git => "https://github.com/whhaijun/HJBaseTableView.git", :tag => spec.version } // 庫的Git 下載地址 和 版本號
spec.source_files = "HJBaseTableView/HJBaseTableView/**/*" // 庫的Git 資源文件(需要暴露的文件路徑,以 podspec 同級別為開始 如 podspec文件 和第一個 HJBaseTableView文件夾 同級別)
spec.swift_version = '4.0' // 可選 ,支持的swift 最低版本
spec.static_framework = true // 是否是靜態(tài)庫
spec.requires_arc = true // 是否是 arc 環(huán)境
spec.dependency 'UITableView+FDTemplateLayoutCell', '1.6' // 可選 ,依賴的第三方庫 UITableView+FDTemplateLayoutCell 和版本號,版本號可選
end
需要注意的點(diǎn):
- 首先創(chuàng)建的
pod庫,最好自己驗(yàn)證一下,是否正確有誤, - 支持的最低
iOS版本 - 支持的
swift最低版本 - 是否有依賴的第三方庫
podspec文件,有很多字段,可以查看其它的文章查閱
創(chuàng)建LICENSE版權(quán)文件



點(diǎn)擊 Review and submit 按鈕提交,然后 commit, push到項(xiàng)目中。
提交tag版本
- 需要注意的是
tag版本要和podspec文件版本保持一致spec.version = "0.0.1" // 庫版本
git tag 0.0.1
git push origin 0.0.1


Releases tag版本


校驗(yàn)podspec文件
以上都準(zhǔn)備好之后,可以開始校驗(yàn)podspec文件并發(fā)布pod庫了。在終端 cd 到本地關(guān)聯(lián)項(xiàng)目路徑中
pod lib lint --allow-warnings

這一步可能會有一些問題,但是當(dāng)時(shí)忘記記錄了,大多數(shù)按照錯誤提示都比較好改,下面有些常見的錯誤:
spec.homepage官網(wǎng)首頁地址錯誤spec.source下載的Git地址不正確- 提示
spec.source_files錯誤,需要注意的是podspec文件和source_files文件是同級別開始的- 如果確認(rèn)
spec.source_files編寫一定沒有錯誤,那么有可能就是沒有上傳tag版本或Releases tag版本版權(quán)文件錯誤或沒有找到
錯誤版權(quán)文件
上傳發(fā)布
再校驗(yàn) podspec文件成功之后,基本就沒有什么問題了,可以大多數(shù)可以一遍成功。
pod trunk push HJBaseTableView.podspec --use-libraries --allow-warnings

如何有錯誤,和上一步一樣,一樣一樣的解決,修改完錯誤,記得更新 tag Edit Release。
沒有問題之后就可以驗(yàn)證是否成功了,可以用 pod search HJBaseTableView 來查看

如果沒有找到,那就更新一下本地 pod 庫
pod repo update
pod install --repo-update
pod repo update或pod install --repo-update,在項(xiàng)目中這兩個些時(shí)候可以等同。如果沒有在項(xiàng)目中,就是用pod repo update更新,更新可能會有點(diǎn)慢。
當(dāng)有新的版本上傳時(shí),本地的項(xiàng)目中想要更換 ,也需要先更新本地pod庫,然后再更新項(xiàng)目 ??梢允褂?pod repo update + pod install 或 直接 pod install --repo-update
pod repo update
pod install --repo-update
pod update HJBaseTableView --verbose --no-repo-update
pod update HJBaseTableView --verbose --no-repo-update 只更新項(xiàng)目中的HJBaseTableView第三方庫,其他的不更新,這樣就不用更新所有版本了。
刪除上傳的Pod庫,或者棄用pod庫
如果我們想刪除一個已有的庫,可以使用下面的指令:
pod trunk delete NAME 0.0.1 刪除某個版本
pod repo remove NAME 刪除某個版本
pod trunk deprecate NAME 棄用某個倉庫,不會刪除,但是是下載時(shí)會有提示已棄用
/// 刪除,后面需要跟上版本號
pod trunk delete LZScaner 0.0.1
/// 刪除某個庫
pod repo remove NAME
/// 棄用某個庫
pod trunk deprecate LZScaner
如果使用 delete 指令會有下面的提醒:
WARNING: It is generally considered bad behavior to remove versions of a Pod that others are depending on!
Please consider using the `deprecate` command instead.
Are you sure you want to delete this Pod version?
>
這時(shí),輸入y,回車即可!
發(fā)布pod庫中遇到的問題
1、運(yùn)行pod lib lint --allow-warnings校驗(yàn) podspec文件時(shí)報(bào)錯
xcodebuild: Returned an unsuccessful exit code. You can use '--verbose' for more information.
嘗試解決:pod spec lint ****.podspec --verbose
2、運(yùn)行pod lib lint --allow-warnings校驗(yàn) podspec文件時(shí)報(bào)錯
* ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code.
嘗試解決:在驗(yàn)證后面加上 --skip-import-validation
pod lib lint --allow-warnings --skip-import-validation
3、發(fā)布時(shí),運(yùn)行pod trunk push HJBaseTableView.podspec --use-libraries --allow-warnings時(shí)報(bào)錯
Authentication token is invalid or unverified. Either verify it with the email that was sent or register a new session.
嘗試解決:第一步 查看
pod trunk me是否可以查看到信息。
如果pod trunk me報(bào)錯, 需要到 注冊的 trunk 郵箱進(jìn)行驗(yàn)證(會有驗(yàn)證郵件)
trunk郵箱驗(yàn)證.png
4、發(fā)布時(shí) pod 成功之后,pod search CMSPaaS 報(bào)錯時(shí)
Unable to find a pod with name, author, summary, or description matching ‘CMSPaaS’或CocoaPods was not able to update the 'cocoapods' repo. If this is an unexpected issue and persists you can inspect it running 'pod repo update --verbose'
嘗試解決:刪除原來的查詢json文件
rm ~/Library/Caches/CocoaPods/search_index.json再次
pod search CMSPaaS
^ 0_0 ^ -- Bright: 祝大家開心快樂每一天。

