從零開始建立CocoaPods私有庫

爲何要建立CocoaPods私有庫?

  • 避免重複的造輪子
  • 節約時間,方便管理本身的代碼
  • 精益求精

建立CocoaPods私有庫

1.建立私有倉庫工程

執行命令pod lib create SmartBeeKit,而後根據實際狀況回答問題,本文以建立SmartBeeKit爲例。ios

2.將編寫好的源碼文件拷貝到SmartBeeKit/Classes目錄下

3.在SmartBeeKit/Example目錄下執行pod install,而後打開SmartBeeKit.xcworkspace工程,編寫測試代碼,run😁,驗證代碼是否導入成功

4.在GitHub或者其餘代碼託管平臺上,建立SmartBeeKit遠程倉庫https://github.com/xxx/SmartBeeKit.git

5.修改SmartBeeKit.podspec文件,裏面 包含了大量的註釋說明以及每一個參數的含義及用法

s.name:名稱,pod search 搜索的關鍵詞
s.version:版本
s.summary:簡介,pod search 搜索的關鍵詞
s.homepage:主頁地址,例如Github地址
s.license:許可證
s.author:做者
s.social_media_url:社交網址
s.platform:平臺
s.source:Git倉庫地址,例如在Github地址後邊加上 .git 就是Git倉庫地址,常見寫法以下
s.source_files:須要包含的源文件,常見的寫法以下
s.resources:須要包含的圖片等資源文件
s.dependency:依賴庫,不能依賴未發佈的庫
s.dependency:依賴庫,若有多個能夠這樣寫
s.requires_arc:是否要求ARC
複製代碼

6.運行pod lib lint SmartBeeKit.podspec驗證私有庫正確性,出現SmartBeeKit passed validation.表示驗證成功。

7.將包含配置好的 .podspec 的項目提交到第4步建立的倉庫上,並給此次提交打上 tag,到此,私有庫就建立好了,good luck!!!

如何引用本身建立的私有庫?

有兩種方式引用本身建立的私有庫git

1.直接引用,不使用索引庫,所見即所得😁

platform :ios, '9.0'
target 'TestPod' do
    # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
    # use_frameworks!

    # Pods for TestPod
    pod 'SmartBeeKit', :git => 'https://github.com/xxx/SmartBeeKit.git'
end
複製代碼

2.建立私有的cocoapods索引庫,而後在引用它

2.1 在GitHub碼雲等代碼託管開發平臺上創建一個空的倉庫,我建立了一個Rbbin的空倉庫,見下圖

2.2 將本地索引庫與遠程索引庫作關聯

pod repo add Rbbin https://github.com/xxx/Rbbin.gitgithub

能夠用下面的命令,來查看是否關聯成功markdown

pod repooop

能夠用下面的命令,來刪除索引庫測試

pod repo remove [索引庫名字]ui

2.3 將私有倉庫push到索引庫

pod repo push Rbbin SmartBeeKit.podspec url

2.4 配置podfile文件以下,而後pod install
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/xxx/Rbbin.git'

platform :ios, '9.0'

target 'TestPod' do
    # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
    # use_frameworks!

    # Pods for TestPod
    # pod 'SmartBeeKit', :git => 'https://github.com/xxx/SmartBeeKit.git'
    pod 'SmartBeeKit', '~> 0.0.1’
end
複製代碼
2.5 如何更新維護?

若是有新版本了,好比1.0.0,就須要再次執行命令 pod repo push Rbbin SmartBeeKit.podspec,就能夠更新上去.spa

2.6 如何刪除podspec索引庫中的私有倉庫呢?

其實很簡單,只須要cd到~/.cocoapods/repos/Rbbin目錄下,刪掉庫目錄code

rm -rf SmartBeeKit/

而後push到遠端倉庫

git add .
git commit -m "delete SmartBeeKit"
git push origin master
複製代碼

建立本身的公有庫(未完待續...)

相關文章
相關標籤/搜索