製作 Cocoapods 庫

ebamboo發表於2021-07-03

一、準備工作:註冊 trunk

1、更新 cocoapods 至最新版本
2、申請註冊 trunk
pod trunk register email 'name'
3、進入郵箱,點選啟用註冊
4、驗證註冊成功並檢視資訊
pod trunk me

二、原始碼設定

1、使用 GitHub 作為原始碼的遠端倉庫
2、拉取到本地
3、cd 到專案資料夾下
4、建立 spec 檔案
pod spec create 庫名
5、編輯 spec 檔案
這一步很關鍵,需要認真一個一個按需正確編寫
下文附有一個例子可以參考,也可以參考流行的三方庫的 spec 檔案
6、驗證 spec 檔案是否有效
pod lib lint
7、commit 程式碼,並 tag 本次修改,push 至遠端倉庫時選擇一併推送 tag。tag 為庫的版本號

三、上傳 spec 至 cocoapods

1、cd 到 spec 檔案所在目錄
2、上傳 spec 檔案
pod trunk push 或者 pod trunk push 庫名.podspec

四、Demo 測試

1、建立編輯 Podfile
2、pod install --repo-update

注意

1、網路最好開啟 VPN 全域性模式
2、測試時可能需要等待幾分鐘才會生效

Pod::Spec.new do |spec|

  spec.name         = "BBPictureBrowser"
  spec.version      = "1.0.2"
  spec.license      = "MIT"
  spec.summary      = "一個輕量級的圖片瀏覽器"
  spec.author       = { "ebamboo" => "1453810050@qq.com" }
  
  spec.homepage     = "https://github.com/ebamboo/BBPictureBrowser"
  spec.source       = { :git => "https://github.com/ebamboo/BBPictureBrowser.git", :tag => spec.version }

  spec.source_files = "BBPictureBrowser/BBPictureBrowser/*.{h,m}"
  spec.resource     = "BBPictureBrowser/BBPictureBrowser/Resources/*"
  
  spec.platform     = :ios, "11.0"
  spec.requires_arc = true
  spec.dependency "SDWebImage"
  
end

相關文章