有時候我們寫了一個框架想讓別人使用該怎么辦呢?下面就詳細說明步驟
- 在github上創(chuàng)建一個倉庫,注意創(chuàng)建時勾選license選項
- 將你的代碼上傳到github上面,這前一篇文章有說明。在上傳代碼之前要給代碼打上一個tag 因為后面會用到
- 在項目的根目錄下 執(zhí)行 pod spec create ZCRefresh //create后面是你創(chuàng)建的文件名,執(zhí)行該命令后,在項目的根目錄下會出現(xiàn)一個.Podspec文件文件
- 進入該文件,可以使用vim ZCRefresh.Podspec 或者使用xcode 打開。
- 編輯文件內(nèi)容如下
Pod::Spec.new do |s|
s.name = "ZCRefresh" //文件的名字
s.version = "1.02" //版本號:這個可以跟之前上傳到github上打得tag一個版本
s.summary = "A Refresh for iOS platform" //一個描述,可以隨便寫
s.homepage = "https://github.com/MrZhaoCn/Refresh" //github代碼倉庫地址
s.license = "MIT" //注意在創(chuàng)建github倉庫時要選中l(wèi)icense不然后面再檢測時會出現(xiàn) 警告
s.author = { "MrZhao" => "861127175@qq.com" } //這個不用多解釋,大家肯定能看懂
s.platform = :ios, "7.0"
// 這個是關鍵,進入github時選擇下載時會看到一個網(wǎng)址,復制進來,這個tag就是你上傳到github時打上的標記
s.source = { :Git => "https://github.com/MrZhaoCn/ZCRefresh.git}
20160630191020804.png
//這個是你的框架文件夾,我的框架在文件夾ZCRefresh下,最好是你的框架在項目的根目錄下。
s.source_files = "ZCRefresh//.{h,m}"
20160630191301227.png
s.resources = "ZCRefresh/images/.png" //資源
我的框架資源結(jié)構如下
20160630191613024.png
s.requires_arc = true //這個是說明你的框架是否要求arc環(huán)境,根據(jù)你的框架來寫
end
下面是完整的文件內(nèi)容
Pod::Spec.new do |s|
s.name = "ZCRefresh"
s.version = "1.02"
s.summary = "A Refresh for ios platform"
s.homepage = "https://github.com/MrZhaoCn/Refresh"
s.license = "MIT"
s.author = { "MrZhao" => "861127175@qq.com" }
s.platform = :ios, "7.0"
s.source = { :git => "https://github.com/MrZhaoCn/ZCRefresh.git", :tag => "1.02" }
s.source_files = "ZCRefresh/**/*.{h,m}"
s.resources = "ZCRefresh/images/*.png"
s.requires_arc = true
end
6 . 通過第五步你的文件就編輯好了,此時可以驗證一下是否有錯誤
pod spec lint PodName.podspec //后面改成你的文件名
7.如果驗證通過 就可以提交了 先注冊一下pod trunk register 861127175@qq.com 'MrZhao' --description='macbook air'
,把郵箱跟名字換成你的即可,注冊后會收到郵件點進去驗證即可。
8.在工程根目錄(包含有.podspec)下執(zhí)行命令:pod trunk push
至此你的框架就支持cocoapods了,如果提交出現(xiàn)錯誤根據(jù)錯誤提示信息做相應的更改即可。