軍哥昨天搞了半天終于讓自己的框架支持cocoapods了,下面就上教程,方便朋友學習,讓自己的框架支持cocoapods

其實讓自己的工程支持cocoapods很簡單只需要幾步
1.創(chuàng)建.podspec
2.編輯.podspec
3.將自己的項目打成tag
4.驗證
5.注冊CocoaPods
6.發(fā)布
1.代碼提交到github平臺
將自己的代碼上傳到github這里不是唯一的,上傳到任何平臺上都可以,前提是項目是開源的至于怎么將自己的項目提交到github上,稍后會上教程

2.創(chuàng)建.podspec
然后cd到你項目的目錄,執(zhí)行命令,你也可以使用vim創(chuàng)建,只要創(chuàng)建就可以了
// 注 YJSettingTableView 這個是你框架的名稱
$ pod spec create YJSettingTableView
3.編輯.podspec
創(chuàng)建好后打開,刪除注釋, 前面有#的為注釋,如果你想知道每個東西的含義可以了解一下
整理之后的文件
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發(fā)布成功后會@你
s.source:項目的地址
s.source_files:需要包含的源文件
s.resources: 資源文件
s.requires_arc: 是否支持ARC
s.dependency:依賴庫,不能依賴未發(fā)布的庫
s.dependency:依賴庫,如有多個可以這樣寫
例如
s.dependency = 'AFNetworking'
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.創(chuàng)建LICENSE(許可證/授權)文件,此文件必須要有
軍哥在這里被坑過,創(chuàng)建一個文件名字命名為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官方就可以了,提交命令請看下面
- 執(zhí)行命令
//為git打tag, 第一次需要在前面加一個v
git tag "v1.0.0"
//將tag推送到遠程倉庫
git push --tags
7.驗證.podspec文件
- 到此檢查一下你工程下面的文件, 你的項目, .podspec文件, LICENSE文件
-
驗證會先測試本地 .podspec 文件是否存在語法錯誤.
文件目錄
然后執(zhí)行命令
// --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
- 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 "coderYJ" --verbose
注冊完成之后會給你的郵箱發(fā)個郵件,進入郵箱郵件里面有個鏈接,需要點擊確認一下
9.發(fā)布
發(fā)布時會驗證 Pod 的有效性,如果你在手動驗證 Pod 時使用了 --use-libraries 或 --allow-warnings 等修飾符,那么發(fā)布的時候也應該使用相同的字段修飾,否則出現相同的報錯。
// --use-libraries --allow-warnings
pod trunk push YJSettingTableView.podspec
-
驗證中
正在驗證 -
發(fā)布成功
發(fā)布成功 發(fā)布成功后的信息,終端中的信息
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吧
如果出現問題,歡迎咨詢軍哥,定期更新錯誤,大家相互學習
請關注我,聯系方式在我的簡書首頁
持續(xù)更新實用的干貨


