本文主要介紹如何自己寫一個pod,然后注冊到CocoaPods上,并將代碼放到Github上供別人下載。這基本上是任何一個pod的“標準”上架流程。當然你也可以將pod放到其他的git平臺上。
1> 注冊trunk賬號
pod trunk register 您的github郵箱'github的用戶名' --verbose
第一次嘗試的時候可能會報如下錯誤:
[!] There was an error registering with trunk: getaddrinfo: nodename nor servname provided, or not known
可以修改DNS來解決這個問題
1、打開
2、點擊網絡
3、高級
4、DNS? 雙擊DNS服務器進行修改(不要修改太大了例如:223.6.6.6 -> 223.6.6.7)? -> 點擊好 ->應用
5、終端執行命令?
?pod trunk register 您的github郵箱 'github的用戶名' --verbose
注冊成功之后會有如下提示:
[!] Please verify the session by clicking the link in the verification email that has been sent to qcl901028@gmail.com
并向您的郵箱發送一個郵件點擊里面的鏈接激活就可以了
查看個人信息
pod trunk me
2> 添加podspec描述文件
這個文件是為了讓CocoaPods搜索引擎知道代碼作者、名稱、版本號、源代碼地址、依賴庫等等信息。下面是官方的信息文件的例子(你也可以去下面cocoapods的官方網站去查看?http://guides.cocoapods.org?):
1.創建podSpec文件主要用到pod lib工具:
手動創建podSpec文件,your_pod_spec_name 最好和你的庫的名字一樣
pod spec create your_pod_spec_name
這個時候會生成一個文件到本地? your_pod_spec_name.podspec 你可以用記事本打開這個文件(文件位置在你終端操作的目錄下面)如下圖:
找到文件之后,用記事本打開(當然你也可以裝逼的用vim + 文件名的方式打開,然后按1000dd來清楚內容 ?呃呃呃。。。不知道有沒有命令可以刪除全部內容 每次清除的時候都是清除10000行,來達到全部清清空的效果) ,然后全選刪除。?
小小都比一下 我們來看看我們偉大的杰哥是怎么寫這個文件的
Pod::Spec.new do |s|
s.name? ? ? ? = 'MJRefresh'
s.version? ? ? = '3.1.12'
s.summary? ? ? = 'An easy way to use pull-to-refresh'
s.homepage? ? = 'https://github.com/CoderMJLee/MJRefresh'
s.license? ? ? = 'MIT'
s.authors? ? ? = {'MJ Lee' => '199109106@qq.com'}
s.platform? ? = :ios, '6.0'
s.source? ? ? = {:git => 'https://github.com/CoderMJLee/MJRefresh.git', :tag => s.version}
s.source_files = 'MJRefresh/**/*.{h,m}'
s.resource? ? = 'MJRefresh/MJRefresh.bundle'
s.requires_arc = true
end
s.name ?庫名 ?就是將來你要導入文件時候的名字 ?如:pod MJRefresh
s.version 庫的版本號 ?杰哥已經更新到3.1.12
s.summary ?總結 ?寫自己項目的用途的
s.homepage 你的庫的首頁地址? 不明白可以自行打開github MJRefresh 看項目結構
s.license? ? ? = 'MIT' ?這樣寫就行了 ?這個是一個許可證 。不知道有啥作用
s.authors? ? ? = {'用戶名' => 'github郵箱地址'}
s.platform? ? = :ios, '你的庫最低支持的版本'
s.source? ? ? = {:git => '項目首頁地址/庫名.git', :tag => s.version}
s.source_files = 'MJRefresh/**/*.{h,m}' 這個是你的庫文件夾路徑 ?這個表示的是MJRefresh文件夾下的所有.h.m文件 ?
s.resource? ? = 'MJRefresh/MJRefresh.bundle' ?圖片或者一些資源文件的位置路徑
s.requires_arc = true ?是不是arc
當然這些只是一些常用的 (⊙o⊙)…? 暫且稱他為參數吧 (我真不知道這是個什么鳥東西,不知道怎么去稱呼他s.name )。如果需要更多信息 ?用AF 或者sd 一類的第三方去查看寫的什么
額 ,好吧 !廢話過多。。。
2. 驗證podSpec文件是否正確。
pod lib lint?
3.增加git 版本 ??
1、git add -A
2、git commit -m "first commit for version 1.0.0"
3、git push origin master
1、當然,你也可以使用SourceTree等GUI形式的Git客戶端進行代碼的推送操作。
2、確保你所push的代碼已經打上"version tag",也就是給源代碼打上版本號標簽:
4、git tag '1.0.0'
5、git push --tags
3、需要注意的是? 版本最好和podspec文件中的版本保持一致
4. 用trunk推送podspec文件
確保podspec文件已校驗通過之后,用以下命令將該podspec文件上傳至trunk? (your_pod_spec_name.podspec)這個是你自己創建的podspec文件
pod trunk push your_pod_spec_name.podspec
成功之后,就pod Search + 你的庫名 ?看看是不是很驚喜 ?擁有了自己的項目