其實讓自己的工程支持cocoapods很簡單只需要幾步
創建.podspec
編輯.podspec
將自己的項目打成tag
驗證
注冊CocoaPods
發布
1.代碼提交到github平臺
將自己的代碼上傳到github這里不是唯一的,上傳到任何平臺上都可以
2.創建.podspec
然后cd到你項目的目錄,執行命令,你也可以使用vim創建,只要創建就可以了
// 注 YJSettingTableView 這個是你框架的名稱,也是別人搜索的關鍵字名稱
$ pod spec create YJSettingTableView
3.編輯.podspec
創建好后打開,刪除注釋, 前面有#的為注釋,如果你想知道每個東西的含義可以了解一下
整理之后的文件
Pod::Spec.new do |s|
s.name = "YJSettingTableView"
s.version = "1.0.0"
s.ios.deployment_target = '7.0'
s.summary = "A delightful setting interface framework."
s.homepage = "https://github.com/coderYJ/YJSettingTableView"
s.license = { :type => "MIT", :file => "LICENSE" }
s.author = { "coderYJ" => "wenyanjun1314@163.com" }
s.social_media_url = "http://weibo.com/u/5348162268"
s.source = { :git => "https://github.com/coderYJ/YJSettingTableView.git", :tag => s.version }
s.source_files = "YJSettingTableView/*.{h,m}"
s.resources = "YJSettingTableView/YJSettingTableView.bundle"
s.requires_arc = true
end
接下來講解一下每行代碼的含義
s.name:名稱,
pod search 搜索的關鍵詞,注意這里一定要和.podspec的名稱一樣,否則報錯
s.version:版本號
s.ios.deployment_target:支持的pod最低版本
s.summary: 簡介
s.homepage:項目主頁地址
s.license:許可證
s.author:作者
s.social_media_url:社交網址,這里我寫的微博默認是Twitter,如果你寫Twitter的話,你的podspec發布成功后會@你
s.source:項目的地址
s.source_files:需要包含的源文件
s.resources: 資源文件
s.requires_arc: 是否支持ARC
s.dependency:依賴庫,不能依賴未發布的庫
s.dependency:依賴庫,如有多個可以這樣寫
例如
s.dependency = 'AFNetworking'
s.license說明
s.license= { :type => "MIT", :file => "LICENSE" }
這里建議大家這樣寫,如果寫別的會報警告,導致后面一直提交失敗,這里軍哥已經跳了很多坑
source_files說明
寫法及含義建議大家寫第一種或者第二種
"YJSettingTableView/*
""YJSettingTableView/YJSettingTableView/*.{h,m}"
"YJSettingTableView/**/*.h"
“” 表示匹配所有文件
“.{h,m}” 表示匹配所有以.h和.m結尾的文件
“**” 表示匹配所有子目錄
s.source 常見寫法
s.source = { :git => "https://github.com/coderYJ/YJSettingTableView.git", :commit => "68defea" }
s.source = { :git => "https://github.com/coderYJ/YJSettingTableView.git", :tag => 1.0.0 }
s.source = { :git => "https://github.com/coderYJ/YJSettingTableView.git", :tag => s.version }
commit => “68defea” 表示將這個Pod版本與Git倉庫中某個commit綁定
tag => 1.0.0 表示將這個Pod版本與Git倉庫中某個版本的comit綁定
tag => s.version 表示將這個Pod版本與Git倉庫中相同版本的comit綁定
4.創建LICENSE(許可證/授權)文件,此文件必須要有
軍哥在這里被坑過,創建一個文件名字命名為LICENSE,內容為:
只需要把前面的版權改一下就行了,后面的都一樣
Copyright (c) 2011-2016 YJSettingTableView Software Foundation (https://github.com/coderYJ/YJSettingTableView/)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
5.上傳到Git
將包含配置好的 .podspec, LICENSE 的項目提交 Git
6.打tag
因為cocoapods是依賴tag版本的,所以必須打tag,以后再次更新只需要把你的項目打一個tag然后修改.podspec文件中的版本接著提交到cocoapods官方就可以了
執行命令
//為git打tag
$ git tag 1.00
//將tag推送到遠程倉庫
$ git push --tags
7.驗證.podspec文件
到此檢查一下你工程下面的文件, 你的項目 .podspec文件, LICENSE文件驗證會先測試本地 .podspec 文件是否存在語法錯誤.然后執行命令
// --verbose 如果驗證失敗會報錯誤信息
pod spec lint YJSettingTableView.podspec --verbose
驗證過程中:
-> YJSettingTableView
驗證成功后:
YJSettingTableView.podspec passed validation.
驗證失敗:
[!] The spec did not pass validation, due to 1 error.
8.注冊Trunk
trunk需要CocoaPods 0.33版本以上,用pod --version
命令查看版本,
如果版本低,需要升級:
$ sudo gen install cocoapods
$ pod setup
已經注冊過的不需要注冊,怎么看自己有沒有注冊
$ pod trunk me
我的注冊信息
-Name: coderYJ
- Email: [wenyanjun1314@163.com](mailto:wenyanjun1314@163.com)
- Since: August 12th, 04:37
- Pods:
- YJSettingTableView
- Sessions:
- August 12th, 04:37 - Unverified. IP: 113.111.64.45
Description: macbook pro
- August 12th, 04:39 - December 18th, 21:11. IP: 113.111.64.45
Description: macbook pro
注冊
// 加上--verbose可以輸出詳細debug信息,方便出錯時查看。
// 郵箱 一定要寫有效的郵箱,待會需要驗證
// 名稱隨意寫
pod trunk register [wenyanjun1314@163.com](mailto:wenyanjun1314@163.com) "coderYJ" --verbose
注冊完成之后會給你的郵箱發個郵件,進入郵箱郵件里面有個鏈接,需要點擊確認一下
9.發布
發布時會驗證 Pod 的有效性,如果你在手動驗證 Pod 時使用了 —use-libraries 或 —allow-warnings 等修飾符,那么發布的時候也應該使用相同的字段修飾,否則出現相同的報錯
// --use-libraries --allow-warnings
$ pod trunk push YJSettingTableView.podspec
驗證中
發布成功
發布成功后的信息
bogon:YJSettingTableView simplyou$ pod trunk push YJSettingTableView.podspec
Updating spec repo `master`
CocoaPods 1.1.0.beta.1 is available.
To update use: `gem install cocoapods --pre`
[!] This is a test version we'd love you to try.
For more information see http://blog.cocoapods.org
and the CHANGELOG for this version http://git.io/BaH8pQ.
Validating podspec
[!] Unable to load a specification for the plugin `/Library/Ruby/Gems/2.0.0/gems/cocoapods-deintegrate-1.0.0`
-> YJSettingTableView (1.0.0)
[!] Unable to accept duplicate entry for: YJSettingTableView (1.0.0)
[!] Unable to read the license file `/private/var/folders/qr/x09stzhx4rvf8cd4s0nmw8m80000gn/T/CocoaPods/Lint/Pods/YJSettingTableView/LICENSE` for the spec `YJSettingTableView (1.0.0)`
[!] Unable to read the license file `/private/var/folders/qr/x09stzhx4rvf8cd4s0nmw8m80000gn/T/CocoaPods/Lint/Pods/YJSettingTableView/LICENSE` for the spec `YJSettingTableView (1.0.0)`
10.最后一步趕快驗證一下
在終端中輸入命令
$ pod search YJSettingTableView
會出現如下信息
bogon:YJSettingTableView simplyou$ pod search YJSettingTableView
-> YJSettingTableView (1.0.0)
A delightful setting interface framework.
pod 'YJSettingTableView', '~> 1.0.0'
- Homepage: https://github.com/coderYJ/YJSettingTableView
- Source: https://github.com/coderYJ/YJSettingTableView.git
- Versions: 1.0.0 [master repo]
bogon:YJSettingTableView simplyou$
代表你的項目已經支持pod了是不是soeasy啊到此大功告成,小伙伴們趕快讓你的框架支持pod吧如果出現問題,歡迎咨詢軍哥,定期更新錯誤,大家相互學習持續更新實用的干貨
來源:
http://bbs.520it.com/forum.php?mod=viewthread&tid=1886&extra=page%3D1