1. code repository是代碼倉庫,我們把包代碼上傳到這個(gè)倉庫。
2. spec repository是配置倉庫,所有的配置按照包名、版本號(hào)分門別類的存放在這個(gè)倉庫。這個(gè)倉庫只用來存放spec文件,不存放代碼。
制作私有 CocoaPods庫大致需要兩大步操作:
第一步:code repository 代碼庫
-
首先需要在gitlab上創(chuàng)建需要發(fā)布的私有代碼庫

-
clone倉庫到本地(我這里演示的克隆到桌面)
$ git clone http://git.xxxxxxx.com/maling/MGtest.git
完成之后你會(huì)發(fā)現(xiàn) MGtest文件夾??下是一個(gè)空的文件夾,也不完全是空的,還有一個(gè) .git隱藏文件, 如果還是看不到 .git隱藏文件,可以用下面2行命令顯示或者隱藏
//打開隱藏的命令:
defaults write com.apple.finder AppleShowAllFiles -bool true
//關(guān)閉隱藏的命令:
defaults write com.apple.finder AppleShowAllFiles -bool false
由于MGtest文件夾??里面是空,需要自己創(chuàng)建LICENSE和README.md文件,可以從其它地方拷貝進(jìn)來
-
創(chuàng)建
MGtest.podspec說明文件
每個(gè) Pods 遠(yuǎn)程庫必須有且僅有一個(gè)名稱和遠(yuǎn)程庫名保持一致,后綴名為 .podspec 的描述文件。
- cd到當(dāng)前 MGtest 文件夾下
- 命令執(zhí)行
$ pod spec create MGtest就會(huì)得到 MGtest.podspec ,說明文件 如下圖:
其中MGtest文件就是你要發(fā)布使用的庫文件內(nèi)容
補(bǔ)充:pod lib create MGtest可以直接創(chuàng)建倉庫模板,比上面的2步驟方便
- 編輯MGtest.podspec 文件
Pod::Spec.new do |s|
s.name = "MGtest"
s.version = "1.0.0"
s.summary = "The data is being tested and can be modified here."
s.homepage = "http://xxxxxx/maling/MGtest"
s.license = "MIT"
s.license = { :type => "MIT", :file => "LICENSE" }
s.author = { "maling" => "maling@amberweather.com" }
s.platform = :ios, "9.0"
s.source = { :git => "http://xxxxxx/maling/MGtest.git", :tag => s.version }
s.source_files = "MGtest/*.{h,m}"
s.requires_arc = true
end
- 驗(yàn)證 MGtest.podspec 文件是否正確
$ pod lib lint
如果出現(xiàn)MGtest passed validation 說明驗(yàn)證通過,可以繼續(xù)往下進(jìn)行,如下圖

如果有警告,會(huì)導(dǎo)致無法通過,需要添加--allow-warnings
如果使用了c函數(shù)相關(guān)的,靜態(tài)庫,需要添加--use-libraries
如果依賴了私有庫,需要添加私有庫源--sources='https://github.com/CocoaPods/Specs.git, https://github.com/xxxx/xxSpecs.git(私有索引庫地址)
$ pod lib lint --verbose --use-libraries --allow-warnings --sources='https://github.com/CocoaPods/Specs.git,https://github.com/xxxx/xxSpecs.git'
pod lib lint (從本地驗(yàn)證你的pod能否通過驗(yàn)證)
pod spec lint (從本地和遠(yuǎn)程驗(yàn)證你的pod能否通過驗(yàn)證)
pod lib lint --verbose (加--verbose可以顯示詳細(xì)的檢測過程,出錯(cuò)時(shí)會(huì)顯示詳細(xì)的錯(cuò)誤信息)
pod lib lint --allow-warnings (允許警告,用來解決由于代碼中存在警告導(dǎo)致不能通過校驗(yàn)的問題)
pod lib lint --help (查看所有可選參數(shù),可選參數(shù)可以加多個(gè))
$ pod lib lint --verbose --use-libraries --allow-warnings --no-clean
- 驗(yàn)證通過后,把代碼提交到倉庫即可, 并且設(shè)置
tag標(biāo)簽
$ git add .
$ git commit -m "1.0.0"
$ git tag "1.0.0" // 設(shè)置標(biāo)簽
$ git push --tags
$ git push origin master // 提交到遠(yuǎn)程服務(wù)器
刪除tag
刪除本地: git tag -d "1.0.0"
刪除遠(yuǎn)端: git push origin :1.0.0
$ pod spec lint --verbose --use-libraries --allow-warnings --no-clean
如果上面??操作都沒問題的話就可以看到倉庫里面的內(nèi)容了,如下圖:

第二步: spec repository是配置倉庫

MGSpecs倉庫創(chuàng)建好之后也是一個(gè)空的倉庫,主要是存放其他私有庫的spec文件,就如同官方的https://github.com/CocoaPods/Specs是用來存放所有官方的specs文件一樣。
- 添加MGSpecss索引倉庫
$ pod repo add MGSpecs http://xxxxxxxx/maling/MGSpecs.git
注意:上面的命令的解釋如下:
pod repo add REPO_NAME SOURCE_URL
其中的 REPO_NAME 是我們要添加的私有repo的名稱(這里填的是: MGSpecs),后面是倉庫的 gitlab 地址。這里做的其實(shí)是創(chuàng)建的工作,也就是在~/.cocoapods/repos目錄下添加了一個(gè)以你的私有MGSpecs為名的文件夾,但是并沒有添加spec文件。
命令行執(zhí)行前:

命令行執(zhí)行后:多了一個(gè)MGSpecs的空文件夾??

- 將上面創(chuàng)建的 MGtest.podspec 命令行push操作到你的 Spec Repository
命令行:
$ pod repo push MGSpecs MGtest.podspec
這時(shí)候你會(huì)發(fā)現(xiàn)MGSpecs文件夾??有內(nèi)容了如下圖:

這個(gè)時(shí)候執(zhí)行 pod search MGtest操作就可以搜索到上面的MGtest庫了
注意
點(diǎn)開master文件夾下面的specs目錄,其下存放的就是所有提交到 CocoaPods 的開源庫的 podspec 文件的集合。
- 在項(xiàng)目中的Podfile中增加剛剛制作的好的Pod并使用。
source 'https://github.com/CocoaPods/Specs. git' #官方倉庫地址
source ‘http://xxxxxxxx/maling/MGSpecs.git’ #私有倉庫地址
platform :ios, '8.0'
target 'MGDemo' do
pod ‘MGtest’
end
