1.創(chuàng)建私有倉庫
先coding.net
艇潭、OSChina
舔庶、GitHub
或者自己搭建的Git
服務(wù)器上創(chuàng)建一個(gè)私有倉庫秘狞,然后在本地添加倉庫
pod repo add LYSpecs https://git.coding.net/CodingZero/LYSpecs.git
2.創(chuàng)建私有庫
創(chuàng)建私有庫模板
pod lib create VenderName
- 第一個(gè)問題是問你選擇
Swift
還是Objc
構(gòu)建項(xiàng)目。eg: ObjC
hat language do you want to use?? [ Swift / ObjC ]
> ObjC
- 第二個(gè)問題問你是否需要?jiǎng)?chuàng)建一個(gè)Demo項(xiàng)目
eg: Yes
Would you like to include a demo application with your library? [ Yes / No ]
> Yes
- 第三個(gè)問題讓你是否選擇一個(gè)測試框架
eg: None
Which testing frameworks will you use? [ Specta / Kiwi / None ]
> None
- 第四個(gè)問題是否基于View測試
eg: No
Would you like to do view based testing? [ Yes / No ]
> No
- 第五個(gè)問題是詢問 類的前綴
eg: LY
What is your class prefix?
> LY
3.更新發(fā)布私有庫
- 提交代碼
git add -A && git commit -m "Release 1.0.0"
- 打
tag
git tag '1.0.0'
- 把
tag
推到遠(yuǎn)程倉庫
git push --tags
- 將本地的
master
分支推送到遠(yuǎn)程倉庫
git push origin master
- 提交到私有倉庫
pod repo push LYSpecs VenderName.podspec --allow-warnings --verbose
// --allow-warnings : 允許 警告,有一些警告是代碼自身帶的殿漠。
// --use-libraries : 私有庫、靜態(tài)庫引用的時(shí)候加上
// —-verbose : lint顯示詳情
4.使用私有庫
- 用的時(shí)候需要在
Podfile
里添加源
// GitHub地址
source 'https://github.com/CocoaPods/Specs.git'
# ...相關(guān)庫
// 私有庫地址
source 'https://git.coding.net/CodingZero/LYSpecs.git'
# ...私有庫
- 用的時(shí)候在Podfile里引用
pod 'VenderName'
- 開發(fā)模式下測試Pod庫的代碼
pod 'VenderName', :path => '../' # 指定路徑
然后在Example工程目錄下執(zhí)行pod update
命令安裝依賴佩捞,打開項(xiàng)目工程绞幌,可以看到庫文件都被加載到Pods
子項(xiàng)目中了
不過它們并沒有在Pods
目錄下,而是跟測試項(xiàng)目一樣存在于Development Pods/VenderName
中一忱,這是因?yàn)槲覀兪窃诒镜販y試莲蜘,而沒有把podspec
文件添加到Spec Repo
中的緣故。
5.podspec
文件配置說明
#
# Be sure to run `pod lib lint VenderName.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 http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
#名稱
s.name = 'VenderName'
#版本號
s.version = '0.1.0'
#簡介
s.summary = '這個(gè)是我的私有庫項(xiàng)目Demo.'
# 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
這個(gè)是教程的 私有庫項(xiàng)目 學(xué)習(xí)Demo. (主要:比s.summary要長)
DESC
#主頁,這里要填寫可以訪問到的地址帘营,不然驗(yàn)證不通過
s.homepage = 'https://coding.net/CodingZero/VenderName'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
#開源協(xié)議
s.license = { :type => 'MIT', :file => 'LICENSE' }
#作者
s.author = { 'DeveloperLY' => 'coderyliu@gmail.com' }
#項(xiàng)目地址票渠,這里不支持ssh的地址,驗(yàn)證不通過芬迄,只支持HTTP和HTTPS庄新,最好使用HTTPS。
#這里的s.source須指向存放源代碼的鏈接地址,而不是托管spec文件的repo地址
s.source = { :git => 'https://coding.net/CodingZero/VenderName.git', :tag => "0.1.0" }
#s.social_media_url = 'http://weibo.com/lycoder'
#支持的平臺及版本
s.ios.deployment_target = '7.0'
#代碼源文件地址择诈,**/*表示Classes目錄及其子目錄下所有文件械蹋,如果有多個(gè)目錄下則
#用逗號分開,如果需要在項(xiàng)目中分組顯示羞芍,這里也要做相應(yīng)的設(shè)置
s.source_files = "VenderName/Classes/**/*"
#資源文件地址
# s.resource_bundles = {
# 'MyLib' => ['VenderName/Assets/*.png']
# }
#公開頭文件地址
#s.public_header_files = 'VenderName/Classes/**/*.h'
#所需的framework哗戈,多個(gè)用逗號隔開
s.frameworks = 'UIKit'
#依賴關(guān)系,該項(xiàng)目所依賴的其他庫荷科,如果有多個(gè)需要填寫多個(gè)s.dependency
# s.dependency 'AFNetworking', '~> 3.1'
end