創(chuàng)建CocoaPod私有庫的詳細步驟
一. 遠程索引庫
概念:每創(chuàng)建一個組件都會帶有一個 xxx.podspec 的索引文件.專門用來存放這些索引文件的庫就叫做索引庫.我們需要將這些索引文件上傳到遠程索引庫中去才能保證其他開發(fā)者能夠拿來使用.
在GitHub或者其他代碼托管平臺上面創(chuàng)建遠程索引庫
https://github.com/Kinglioney/iOSPodSpecs.git
二. 本地索引庫
與遠程索引庫對應(yīng),本地索引庫是用來存放本地索引文件的庫
- 創(chuàng)建本地索引庫
pod repo 查看本地已經(jīng)有哪些本地索引庫
pod repo add <本地索引庫的名字> <遠程索引庫的地址> 創(chuàng)建本地索引庫并且與遠程索引庫做關(guān)聯(lián)
三. 遠程代碼庫
用來存放組件化的代碼
四. 本地代碼庫
pod lib create <組件名> 會創(chuàng)建一個工程
編譯成功后,將相應(yīng)的文件拖入本地代碼庫中
編譯組件不報錯后,開始修改podspec文件:
a.修改版本號
b.修改項目的簡單概述和詳細描述
c.修改homepage 和 source 地址
d.添加依賴庫
podspec文件的書寫格式(從CocoaPod官網(wǎng)上摘抄的):
A Simple specification.
Pod::Spec.new do |spec|
spec.name = 'libPusher'
spec.version = '1.3'
spec.license = 'MIT'
spec.summary = 'An Objective-C client for the Pusher.com service'
spec.homepage = 'https://github.com/lukeredpath/libPusher'
spec.author = 'Luke Redpath'
spec.source = { :git => 'git://github.com/lukeredpath/libPusher.git', :tag => 'v1.3' }
spec.source_files = 'Library/'
spec.requires_arc = true
spec.dependency 'SocketRocket'
end
A specification with subspecs.
Pod::Spec.new do |spec|
spec.name = 'ShareKit'
spec.source_files = 'Classes/ShareKit/{Configuration,Core,Customize UI,UI}//.{h,m,c}'
...
spec.subspec 'Evernote' do |evernote|
evernote.source_files = 'Classes/ShareKit/Sharers/Services/Evernote//.{h,m}'
end
spec.subspec 'Facebook' do |facebook|
facebook.source_files = 'Classes/ShareKit/Sharers/Services/Facebook//.{h,m}'
facebook.compiler_flags = '-Wno-incomplete-implementation -Wno-missing-prototypes'
facebook.dependency 'Facebook-iOS-SDK'
end
...
end
- 編譯通過后,提交組件到遠程代碼庫并打tag
git add .
git commit -m "注釋說明"
git remote add origin <遠程代碼倉庫地址>
git push origin master
git tag <版本號> (此處的版本號必須和podspec里面寫的版本號一致)
git push --tags
5.通過 pod spec lint --verbose --allow-warnings 命令來驗證podspec索引文件是否有報錯
6.驗證通過后,提交組件
注意:此處有一點點不同的地方,如果你希望把組件開源給所有的開發(fā)者使用,可以使用Trunk提交組件 pod trunk push <索引文件的名字>,這樣的話在第7步中就不需要指定地址了;
如果你希望組件只能在公司內(nèi)部使用,是私有的不開源.pod repo push <本地索引庫名字> <索引文件的名字> --verbose --allow-warnings 提交索引文件到遠程索引庫
7.使用的時候和CocoaPod引入第三方一樣,需要在Podfile中指定組件遠程索引庫的地址,如果不指定默認就會從master的索引庫中查找就會報錯找不到該組件
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/Kinglioney/iOSPodSpecs.git'