開發(fā)中,如果有比較成熟的組件或代碼庫想要開放給別人使用,制作成pod庫是很好的選擇:一方面便于用戶使用,另一方面版本管理很輕松。最近倒騰了兩個自己的開源庫,現(xiàn)在總結(jié)下制作過程,方便以后查看使用。
注冊Trunk
下面是注冊郵箱和用戶名的命令,將neebel@163.com替換成你自己的郵箱,將neebel替換成你自己的用戶名:
pod trunk register neebel@163.com 'neebel' --verbose
可以用下面的命令查看注冊信息,確保注冊成功了:
pod trunk me
成功的截圖是這個樣子的:
pod0.png
Github上創(chuàng)建工程并拷貝到本地
這一步就不啰嗦了,需要注意的是記得給項目加上MIT協(xié)議,README最好也加上,可以當做項目主頁的介紹
創(chuàng)建podspec文件
在命令行 cd 到剛才拷貝到本地的工程文件的根目錄,執(zhí)行下面的命令,NBLFileExplorer替換成你自己的項目名稱:
pod spec create NBLFileExplorer
然后編輯剛剛生成的創(chuàng)建podspec文件(可選)
Pod::Spec.new do |s|
s.name = "NBLFileExplorer" //項目的名稱
s.version = "0.0.3" //版本號
s.summary = "an iOS tool for manager sandbox file" //項目摘要
s.description = <<-DESC
manager sandbox file //項目描述
DESC
s.homepage = "https://github.com/neebel/NBLFileExplorer" //項目首頁地址
s.license = "MIT" //協(xié)議
s.author = { "neebel" => "neebel@163.com" } //作者信息
s.platform = :ios, "7.0" //支持的版本
s.source = { :git => "https://github.com/neebel/NBLFileExplorer.git", :tag => "#{s.version}" } //項目地址 tag
s.source_files = "Classes", "Classes/**/*.{h,m}" //類文件存放位置
s.exclude_files = "Classes/Exclude"
s.resources = "icon.bundle" //bundle資源位置
把自己需要公開的源碼和資源放到podspec文件聲明的對應(yīng)的位置
提交項目的修改到Github
記得打tag
git commit -m "Release 0.0.3"
git tag 0.0.3
git push --tags
git push origin master
驗證podspec
pod spec lint NBLFileExplorer.podspec
驗證結(jié)果有警告的話可以用下面的命令:
pod spec lint NBLFileExplorer.podspec --allow-warnings
成功的話會顯示 NBLFileExplorer passed validation
trunk push 到 cocoaPods
pod trunk push NBLFileExplorer.podspec
成功后搜索看
pod search NBLFileExplorer
如果能搜索到最好,搜索不到的話執(zhí)行下pod setup再搜索,第一次執(zhí)行pod setup時可能會久一點,如果pod setup后還搜索不到,找到這個路徑/Users/neebel/Library/Caches/CocoaPods下(neebel需要替換成你自己的電腦用戶名)的search_index.json文件刪除掉再搜索
至此,我們自己公開的項目就可以應(yīng)用到他人的項目中了