兩個概念:
1.code repository是代碼倉庫外臂,我們把包代碼上傳到這個倉庫致盟。
2.spec repository是配置倉庫臂痕,所有的配置按照包名、版本號分門別類的存放在這個倉庫囊骤。這個倉庫只用來存放spec文件晃择,不存放代碼。
步驟
第一步:制作cocopods的依賴庫也物,也就是code repository宫屠。
創(chuàng)建一個私有的project
把倉庫clone到本地??git clone xxxx(倉庫地址)
//打開隱藏文件的命令:
defaults write com.apple.finder AppleShowAllFiles -bool true
//關(guān)閉隱藏文件的命令:
defaults write com.apple.finder AppleShowAllFiles -bool false
把代碼XQPhotoBrowse拖到此處,并寫一個demo
創(chuàng)建.podspec滑蚯、LICENSE浪蹂、README.md3 個文件??
每個 Pods 依賴庫必須有且僅有一個名稱和依賴庫名保持一致,后綴名為 .podspec 的描述文件告材,如PhotoLibraryTT.podspec
.podspec創(chuàng)建有2種方法
1.直接copy一份乌逐,并修改里面的內(nèi)容
2.執(zhí)行pod spec create PhotoLibraryTT,創(chuàng)建一個新的
Pod::Spec.new do |s|
? s.name? ? ? ? = "PhotoLibraryTT"
? s.version? ? ? = "1.0.3"
? s.summary? ? ? = "A short description of PhotoLibrary."
? s.homepage? ? = "https://xxxxx"
? s.license? ? ? = "MIT"
? s.author? ? ? ? ? ? = { "xx" => "x'x@qq.com" }
? s.platform? ? = :ios, "8.0"
? s.source? ? ? = { :git => "https://xxxx.git", :tag => "#{s.version}" }
? s.source_files? = "PhotoLibrary/XQPhotoBrowse", "XQPhotoBrowse/**/*.{h,m}"
? s.dependency 'SDWebImage'
end
.podspec詳解
驗證podspec的有效性创葡。
pod lib lint?
如果有警告,會導(dǎo)致無法通過绢慢,需要添加--allow-warnings
如果使用了c函數(shù)相關(guān)的灿渴,需要添加--use-libraries
如果依賴了私有庫,需要添加庫的源--sources='https://xxxx'
pod lib lint --allow-warnings pod lib lint --sources='https://xxxx' --use-libraries --allow-warnings
驗證通過后胰舆,把代碼提交到倉庫即可
git add -A && git commit -m "add pod files"
git push origin master
git tag -a v1.0.3 -m “1.0.3版本”? //一定要打tag
第二步?創(chuàng)建并設(shè)置一個私有的Spec Repository
在gitlab上創(chuàng)建一個空的倉庫骚露,命名為Specs,這個倉庫是用來存放我們自己所有的私有庫的spec文件缚窿,就如同官方的https://github.com/CocoaPods/Specs是用來存放所有官方的specs文件一樣棘幸。
在終端執(zhí)行命令:
pod repo add Specs http://xxx.git
注意:上面的命令的解釋如下:
pod repo add REPO_NAME SOURCE_URL
其中的 REPO_NAME 是我們要添加的私有repo的名稱(這里我們待會填的是:Specs),后面是倉庫的 gitlab 地址倦零。這里做的其實是創(chuàng)建的工作误续,也就是在~/.cocoapods/repo目錄下添加了一個以你的私有repo為名的文件夾,但是并沒有添加spec文件扫茅。
至此蹋嵌,我們已經(jīng)在本地得到我們自己的私有倉庫 Specs ,這是一個空的倉庫葫隙。
添加 剛才第四步創(chuàng)建的 PhotoLibraryTT.podspec 到你的 Spec Repository栽烂。
pod repo push Specs PhotoLibraryTT.podspec
如果有警告,會導(dǎo)致無法通過,需要添加--allow-warnings
如果使用了c函數(shù)相關(guān)的腺办,需要添加--use-libraries
pod repo push Specs PhotoLibraryTT.podspec --use-libraries --allow-warnings
pod search PhotoLibraryTT
在個人項目中的Podfile中增加剛剛制作的好的Pod并使用焰手。
source 'https://xxxxxxx.git'? //私有庫地址
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
inhibit_all_warnings!
def default_pods
? ? pod "PhotoLibraryTT"
end
target ‘Demo’ do
? ? default_pods
end