3分鐘讓你的框架支持cocoapods

其實(shí)讓自己的工程支持cocoapods很簡(jiǎn)單只需要幾步

創(chuàng)建.podspec

編輯.podspec

將自己的項(xiàng)目打成tag

驗(yàn)證

注冊(cè)CocoaPods

發(fā)布

1.代碼提交到github平臺(tái)

將自己的代碼上傳到github這里不是唯一的,上傳到任何平臺(tái)上都可以

,前提是項(xiàng)目是開(kāi)源的至于怎么將自己的項(xiàng)目提交到github上,自己百度吧
你自己的項(xiàng)目

2.創(chuàng)建.podspec

然后cd到你項(xiàng)目的目錄,執(zhí)行命令,你也可以使用vim創(chuàng)建,只要?jiǎng)?chuàng)建就可以了

// 注 YJSettingTableView 這個(gè)是你框架的名稱(chēng),也是別人搜索的關(guān)鍵字名稱(chēng)

$ pod spec create YJSettingTableView

3.編輯.podspec

創(chuàng)建好后打開(kāi),刪除注釋, 前面有#的為注釋,如果你想知道每個(gè)東西的含義可以了解一下
整理之后的文件

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

接下來(lái)講解一下每行代碼的含義
s.name:名稱(chēng),
pod search 搜索的關(guān)鍵詞,注意這里一定要和.podspec的名稱(chēng)一樣,否則報(bào)錯(cuò)
s.version:版本號(hào)
s.ios.deployment_target:支持的pod最低版本
s.summary: 簡(jiǎn)介
s.homepage:項(xiàng)目主頁(yè)地址
s.license:許可證
s.author:作者
s.social_media_url:社交網(wǎng)址,這里我寫(xiě)的微博默認(rèn)是Twitter,如果你寫(xiě)Twitter的話,你的podspec發(fā)布成功后會(huì)@你
s.source:項(xiàng)目的地址
s.source_files:需要包含的源文件
s.resources: 資源文件
s.requires_arc: 是否支持ARC
s.dependency:依賴(lài)庫(kù),不能依賴(lài)未發(fā)布的庫(kù)
s.dependency:依賴(lài)庫(kù),如有多個(gè)可以這樣寫(xiě)
例如

s.dependency = 'AFNetworking'

s.license說(shuō)明
s.license= { :type => "MIT", :file => "LICENSE" }
這里建議大家這樣寫(xiě),如果寫(xiě)別的會(huì)報(bào)警告,導(dǎo)致后面一直提交失敗,這里軍哥已經(jīng)跳了很多坑
source_files說(shuō)明

寫(xiě)法及含義建議大家寫(xiě)第一種或者第二種

"YJSettingTableView/*

""YJSettingTableView/YJSettingTableView/*.{h,m}"

"YJSettingTableView/**/*.h"

” 表示匹配所有文件
.{h,m}” 表示匹配所有以.h和.m結(jié)尾的文件
“**” 表示匹配所有子目錄
s.source 常見(jiàn)寫(xiě)法

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” 表示將這個(gè)Pod版本與Git倉(cāng)庫(kù)中某個(gè)commit綁定
tag => 1.0.0 表示將這個(gè)Pod版本與Git倉(cāng)庫(kù)中某個(gè)版本的comit綁定
tag => s.version 表示將這個(gè)Pod版本與Git倉(cāng)庫(kù)中相同版本的comit綁定

4.創(chuàng)建LICENSE(許可證/授權(quán))文件,此文件必須要有

軍哥在這里被坑過(guò),創(chuàng)建一個(gè)文件名字命名為L(zhǎng)ICENSE,內(nèi)容為:
只需要把前面的版權(quán)改一下就行了,后面的都一樣

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 的項(xiàng)目提交 Git

6.打tag

因?yàn)閏ocoapods是依賴(lài)tag版本的,所以必須打tag,以后再次更新只需要把你的項(xiàng)目打一個(gè)tag然后修改.podspec文件中的版本接著提交到cocoapods官方就可以了
執(zhí)行命令

//為git打tag

$ git tag 1.00 

//將tag推送到遠(yuǎn)程倉(cāng)庫(kù)

$ git push --tags

7.驗(yàn)證.podspec文件

到此檢查一下你工程下面的文件, 你的項(xiàng)目 .podspec文件, LICENSE文件驗(yàn)證會(huì)先測(cè)試本地 .podspec 文件是否存在語(yǔ)法錯(cuò)誤.

然后執(zhí)行命令

// --verbose 如果驗(yàn)證失敗會(huì)報(bào)錯(cuò)誤信息

pod spec lint YJSettingTableView.podspec --verbose

驗(yàn)證過(guò)程中:

-> YJSettingTableView

驗(yàn)證成功后:

YJSettingTableView.podspec passed validation.
Paste_Image.png

驗(yàn)證失敗:

[!] The spec did not pass validation, due to 1 error.

8.注冊(cè)Trunk

trunk需要CocoaPods 0.33版本以上,用pod --version
命令查看版本,

如果版本低,需要升級(jí):

$ sudo gen install cocoapods

$ pod setup

已經(jīng)注冊(cè)過(guò)的不需要注冊(cè),怎么看自己有沒(méi)有注冊(cè)

$ pod trunk me

我的注冊(cè)信息

-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

注冊(cè)

// 加上--verbose可以輸出詳細(xì)debug信息,方便出錯(cuò)時(shí)查看。

// 郵箱 一定要寫(xiě)有效的郵箱,待會(huì)需要驗(yàn)證

// 名稱(chēng)隨意寫(xiě)

pod trunk register [wenyanjun1314@163.com](mailto:wenyanjun1314@163.com) "coderYJ" --verbose

注冊(cè)完成之后會(huì)給你的郵箱發(fā)個(gè)郵件,進(jìn)入郵箱郵件里面有個(gè)鏈接,需要點(diǎn)擊確認(rèn)一下

9.發(fā)布

發(fā)布時(shí)會(huì)驗(yàn)證 Pod 的有效性,如果你在手動(dòng)驗(yàn)證 Pod 時(shí)使用了 —use-libraries 或 —allow-warnings 等修飾符,那么發(fā)布的時(shí)候也應(yīng)該使用相同的字段修飾,否則出現(xiàn)相同的報(bào)錯(cuò)

// --use-libraries --allow-warnings

$ pod trunk push YJSettingTableView.podspec

驗(yàn)證中

Paste_Image.png

發(fā)布成功

Paste_Image.png

發(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.最后一步趕快驗(yàn)證一下

在終端中輸入命令

$ pod search YJSettingTableView

會(huì)出現(xiàn)如下信息

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$

代表你的項(xiàng)目已經(jīng)支持pod了是不是soeasy啊到此大功告成,小伙伴們趕快讓你的框架支持pod吧如果出現(xiàn)問(wèn)題,歡迎咨詢(xún)軍哥,定期更新錯(cuò)誤,大家相互學(xué)習(xí)持續(xù)更新實(shí)用的干貨

來(lái)源:
http://bbs.520it.com/forum.php?mod=viewthread&tid=1886&extra=page%3D1

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容