問題
1.iOS 私有庫存在的意義
2.整么搭建一個iOS私有庫呢
答案
1.iOS 私有庫存在的意義
當(dāng)我們到達(dá)一家新的工作單位之后净当,特別是公司沒有iOS項目基礎(chǔ)的時候,為了公司項目有技術(shù)積累扒俯,作為一個有信仰的iOS開發(fā)人員就需要搭建公司的 私有庫了展融。搭建私有庫的好處就不用我多說了。
2.整么搭建一個iOS私有庫呢
2.1 最終結(jié)果顯示
Tip: cocoapod 整么安裝弊攘,這里就不做詳細(xì)解釋了牵辣,作為一個iOS開發(fā)人員摔癣,這個是最基礎(chǔ)的工具,我就當(dāng)你掌握這些基本知識了
假設(shè)我們開發(fā)了一個私有庫 LAAlamofire 最終結(jié)果應(yīng)該如下圖1.1.png,LASpec 是我們的索引庫纬向,LAAlamofire 使我們自己開發(fā)的庫
2.2 創(chuàng)建流程
- 1.創(chuàng)建自己的索引庫 LASpec
在任意目錄下執(zhí)行如下命令:
pod repo add LASpec https://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@github.com/MMSuperD/LASpec.git
索引庫的名字: LASpec
索引庫的地址: https://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@github.com/MMSuperD/LASpec.git
如果出現(xiàn)如下錯誤 :fatal: unable to access 'https://github.com/MMSuperD/LASpec.git/': Error in the HTTP2 framing layer
解決方案: 多嘗試幾次择浊,換個網(wǎng)絡(luò)嘗試
成功后的結(jié)果是:在 ~/.cocoapods/repos目錄下面新增了 一個 LASpec 文件夾
- 2.創(chuàng)建自己的代碼倉庫LAAlamofire
在桌面創(chuàng)建自己的代碼文件夾:cd 到自己的文件夾目錄執(zhí)行如下代碼:
pod lib create LAAlamofire
代碼庫的名字: LAAlamofire
如果出現(xiàn) 錯誤: fatal: unable to access 'https://github.com/CocoaPods/pod-template.git/': Error in the HTTP2 framing layer
同樣的方式切換網(wǎng)絡(luò),多嘗試幾次
過長中:
What platform do you want to use?? [ iOS / macOS ]
> iOS
What language do you want to use?? [ Swift / ObjC ]
> Swift
Would you like to include a demo application with your library? [ Yes / No ]
> Yes
Which testing frameworks will you use? [ Quick / None ]
> None
Would you like to do view based testing? [ Yes / No ]
> Yes
到這里基本上我們的本地 pod LAAlamofire逾条,基本已經(jīng)創(chuàng)建完畢了
- 3.修改自己的本地代碼庫LAAlamofire
LAAlamofire.podspec 文件
核心點(具體什么意思自行查閱):
s.version = '0.1.1'
s.source = { :git => 'https://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@github.com/MMSuperD/LAAlamofire.git', :tag => s.version.to_s }
s.ios.deployment_target = '15.0'
#
# Be sure to run `pod lib lint LAAlamofire.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 = 'LAAlamofire'
s.version = '0.1.1'
s.summary = 'A short description of LAAlamofire.'
# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!
s.description = <<-DESC
TODO: Add long description of the pod here.
DESC
s.homepage = 'https://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@github.com/MMSuperD/LAAlamofire.git'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'fan' => 'shdjxywd@163.com' }
s.source = { :git => 'https://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@github.com/MMSuperD/LAAlamofire.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.ios.deployment_target = '15.0'
s.source_files = 'LAAlamofire/Classes/**/*'
# s.resource_bundles = {
# 'LAAlamofire' => ['LAAlamofire/Assets/**/*']
# }
# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
# s.dependency 'AFNetworking', '~> 2.3'
s.dependency 'Alamofire', '~> 5.6.4'
end
- 4.把我們本地LAAlamofire的代碼推到遠(yuǎn)端倉庫
首先 pod install
git add .
git commit -m "init"
git remote add origin https://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@github.com/MMSuperD/LAAlamofire.git
git push origin main -f (這里第一次強制推送到 遠(yuǎn)端如果你不強制推送到遠(yuǎn)端琢岩,那你就一步一步拉 之后在推 git pull origin main --allow-unrelated-histories --no-rebase,建議強制推送)
自己打tag: git tag 0.1.1
推送tag:git push origin --tags
- 5.本地庫,遠(yuǎn)程庫校驗
本地庫校驗
pod lib lint LAAlamofire.podspec --verbose --allow-warnings
遠(yuǎn)端庫校驗
pod spec lint --verbose --allow-warnings
- 6.推送本地庫在索引庫中更新
pod repo push LASpec LAAlamofire.podspec --allow-warnings