首先來說說什么是私有庫
顧名思義,就是你的私人代碼倉庫,而不是開源出去讓大家都能看到并參與開發(fā)的項目。私有倉庫可以進(jìn)行權(quán)限控制,只有擁有權(quán)限的人才能訪問并修改它,也就是我們所說的合作者。
私有庫不在cocoaPods的官方Repo倉庫中,而是在自建的spec repo中,庫索引是以 *.podspec文件形式存在,自建的spec repo放在路徑~/.cocoapods/repos下,與master同級,其鏈接的遠(yuǎn)程倉庫可以是公開的,也可以是私有的。
創(chuàng)建pod庫
創(chuàng)建私有庫有兩種方案,第一種方案手動創(chuàng)建 podspec與自己私有倉庫進(jìn)行關(guān)聯(lián),第二種直接使用cocoapods創(chuàng)建
方案一
首先選擇在xcode里新建framework項目,并且在公司倉庫gitLab新建兩個遠(yuǎn)程倉庫(索引庫、代碼庫)用git將本地framework項目推入遠(yuǎn)端
在用終端本地執(zhí)行
#用于創(chuàng)建一個新的 Pod(即一個 iOS 或 macOS 的庫或框架)的規(guī)范文件(`.podspec` 文件)
pod spec create PodName
在.podspec里面進(jìn)行編輯,稍后會詳細(xì)講解 podspec文件內(nèi)容
最后在終端執(zhí)行查看當(dāng)前pod文件是否規(guī)范
#用于檢查一個 Pod 的規(guī)范文件(`.podspec` 文件)是否符合規(guī)范和要求
pod spec lint PodName.podspec
如果編譯成功,符合規(guī)范要求就可以提交pod
pod repo push 索引庫 podName.podspec--verbose--use-libraries--allow-warning
方案二
1.直接使用cocoapods創(chuàng)建
pod lib create PodName
2.然后依次輸入,執(zhí)行即可
What platform do you want to use?? [ iOS / macOS ]
> iOS
What language do you want to use?? [ Swift / ObjC ]
> ObjC
Would you liketo include a demo application with your library? [ Yes / No ]
> YES
Which testing frameworks will you use? [ Specta / Kiwi / None ]
> None
Would you like to do view based testing? [ Yes / No ]
> No
What is your class prefix?
> xx
3.添加庫文件。
成功后會創(chuàng)建出一個pod_test工程,目錄結(jié)構(gòu)如下

將編寫好的一些文件拉入pod_test/classes中。

Example是創(chuàng)建Pods工程時生成的一個工程,用于驗證添加的庫文件是否能正常使用。Example目錄下Podfile文件中自動設(shè)置了pod_test依賴,如下:
target 'pod_test_Example' do
pod 'pod_test', :path => '../' #自動添加了
cd Example文件夾下,終端執(zhí)行pod install或pod update,安裝pod_test依賴就可以查看在項目中應(yīng)用了
提交pods庫到github上。打標(biāo)簽,推送到遠(yuǎn)程。
重點:tag打的版本號必須和podspec中的s.version值相同
git tag
git tag '0.1.0'
git tag
git push origin 0.1.0
刪除本地tag git tag -d 0.1.0
刪除遠(yuǎn)端tag git push origin :refs/tags/0.1.0
.podspec文件配置
#
# Be sure to run `pod lib lint SYCoreKit.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'xxxxx' #搜索的關(guān)鍵詞,注意這里一定要和.podspec的名稱一樣
s.version = '0.0.1' #版本號,每一個版本對應(yīng)一個tag
s.summary = "iOS框架" #項目簡介
s.description = "iOS框架" #pod詳細(xì)描述
s.homepage = 'http://114.116.222.206:9002/zhangchao/siyucorekit.git' #項目主頁地址
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' } #許可證
s.author = { 'superMan' => 'xxxxxxxx' }#作者
s.source = { :git => 'http://xxx.git', :tag => s.version.to_s }#項目的地址
s.social_media_url = 'https://twitter.com/xxx'#作者社交地址
# s.pod_target_xcconfig = { 'VALID_ARCHS' => 'arm64'} 是修改當(dāng)前pod工程中的項目設(shè)置
# s.user_target_xcconfig = { 'VALID_ARCHS' => 'arm64','EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64'} 是修改當(dāng)前用戶工程中的項目設(shè)置
s.ios.deployment_target = '12.0' #支持的pod最低版本
s.static_framework = true #動態(tài)庫模式pod
s.requires_arc = true # 是否啟用ARC
s.source_files = 'SYCoreKit/Classes/**/*' #需要包含的源文件
# s.resource_bundles = {
# 'SYCoreKit' => ['SYCoreKit/Assets/*.png']
# } 資源文件
# s.public_header_files = 'Pod/Classes/**/*.h' #標(biāo)記公共頭文件列表
s.ios.frameworks = "UIKit", "Foundation" #支持的系統(tǒng)框架
s.dependency 'YYModel', '1.0.4'#三方依賴
end
檢查規(guī)范
pod spec lint PodName.podspec
提交pod
pod repo push 索引庫 podName.podspec--verbose--use-libraries--allow-warning