前言
一般而言,大多數開源框架都是託管在GitHub上,然而光是託管上去,並不能直接使用CocoaPods提供版本支持,所以需要開發人員通過一系列操作來提供支持。
正文
假設已有一個開源框架在GitHub上,名稱姑且稱之爲HelloWorldFramework,首先在將代碼clone到本地:
git clone [email protected]:fangzhenxing/HellloWorldFramework.git
然後在GitHub上創建一個release版本:
然後在工程主目錄下使用命令生成specs文件:
pod spec create HellloWorldFramework
specs文件會自動生成在工程目錄中,然後可以根據需要進行配置:
Pod::Spec.new do |spec|
spec.name = "HellloWorldFramework"
spec.version = "1.0.0"
spec.summary = "print 'hello world'."
spec.homepage = "https://github.com/fangzhenxing/HellloWorldFramework"
spec.license = "MIT"
spec.author = { "fangzhenxing" => "[email protected]" }
spec.ios.deployment_target = "8.0"
spec.source = { :git => "https://github.com/fangzhenxing/HellloWorldFramework.git", :tag => "#{spec.version}" }
spec.source_files = "HellloWorldFramework/HellloWorldFramework/*.{h,m}"
spec.requires_arc = true
end
使用命令校驗specs文件是否編寫有錯誤:
pod lib lint --allow-warnings --skip-import-validation
如果出現以下內容則表示校驗通過:
HellloWorldFramework passed validation.
然後創建一個CocoaPods賬號,之後在郵箱驗證一下就可以了:
pod trunk register 你的郵箱 '用戶名' —description='描述信息'
然後將specs推送到GitHub上:
pod trunk push HellloWorldFramework.podspec --allow-warnings
這樣,開源項目對CocoaPods的支持就完成了。
測試
新建一個測試項目HelloWorldTest,編寫Podfile文件內容如下:
# Uncomment the next line to define a global platform for your project
platform :ios, '8.0'
target 'HelloWorldTest' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for HelloWorldTest
pod 'HellloWorldFramework'
end
然後使用命令將框架pull到本地:
pod install --repo-update
就大功告成了!
後續
後面將會增加pod多個release版本下如何處理的問題,以及詳細解析specs所有配置項的含義和如何去使用,敬請期待......