將自己的代碼發布到CocoaPods上

1,CocoaPods的簡單介紹以及使用

我這篇文章主要介紹如何將項目發布到CocoaPods上,安裝以及簡單實用我介紹幾個博客給大家。其中如果你遇到問題還是可以看下面的評論,如果實在不行stackoverflow一定能夠幫你解決。

首先是安裝以及簡單使用的博客:http://www.lxweimin.com/p/f5536485e3a0
其次是更新的博客:http://www.lxweimin.com/p/f5536485e3a0

最后我貼上我這個工程寫的的pod文件

source 'https://git.coding.net/hging/Specs.git'
platform :ios, '8.0'

inhibit_all_warnings!
target 'LLToast’ do

pod 'pop', '~> 1.0'

end

2,將自己的代碼發布到CocoaPods上

2.1 創建自己的github倉庫

CocoaPods都托管在github上(官方鏈接),所有的Pods依賴庫都依賴github,因此我們需要創建一個github,如圖

創建github repository

2.2將倉庫clone到本地

git clone https://github.com/lilianmao/LLToast

2.3向git倉庫添加創建Pods依賴庫的所有文件

2.3.1本地倉庫更新

首先將自己寫的框架復制到你創建的本地倉庫里,這里我直接賦值粘貼了,這里大家最好如下圖放置,因為這樣可以方便別人看懂你的項目,一個license,一個readme,一個你的podspec文件(這個文件的生成我在后面會講的),一個項目的demo,另一個是你的框架。


文件夾目錄

2.3.2創建podspec文件,并且重寫這個文件

創建這個文件

pod spec create LLToast  

修改podspec文件

#
#  Be sure to run `pod spec lint LLToast.podspec' to ensure this is a
#  valid spec and to remove all comments including this before submitting the spec.
#
#  To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
#  To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
#

Pod::Spec.new do |s|

  # ―――  Spec Metadata  ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  These will help people to find your library, and whilst it
  #  can feel like a chore to fill in it's definitely to your advantage. The
  #  summary should be tweet-length, and the description more in depth.
  #

  s.name         = "LLToast"
  s.version      = "1.0.0"
  s.summary      = "A simple LLToast."

  # This description is used to generate tags and improve search results.
  #   * Think: What does it do? Why did you write it? What is the focus?
  #   * Try to keep it short, snappy and to the point.
  #   * Write the description between the DESC delimiters below.
  #   * Finally, don't worry about the indent, CocoaPods strips it!
  s.description  = <<-DESC
                    This is a simple toast.
                    這是一個簡單的toast
                   DESC

  s.homepage     = "https://github.com/lilianmao/LLToast"
  # s.screenshots  = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"


  # ―――  Spec License  ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Licensing your code is important. See http://choosealicense.com for more info.
  #  CocoaPods will detect a license file if there is a named LICENSE*
  #  Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
  #

  s.license      = "MIT"
  # s.license      = { :type => "MIT", :file => "FILE_LICENSE" }


  # ――― Author Metadata  ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Specify the authors of the library, with email addresses. Email addresses
  #  of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
  #  accepts just a name if you'd rather not provide an email address.
  #
  #  Specify a social_media_url where others can refer to, for example a twitter
  #  profile URL.
  #

  s.author             = { "lilin" => "1911932429@qq.com" }
  # Or just: s.author    = "lilin"
  # s.authors            = { "lilin" => "1911932429@qq.com" }
  # s.social_media_url   = "http://twitter.com/lilin"

  # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  If this Pod runs only on iOS or OS X, then specify the platform and
  #  the deployment target. You can optionally include the target after the platform.
  #

  # s.platform     = :ios
  s.platform       = :ios, '8.0'

  #  When using multiple platforms
  # s.ios.deployment_target = "8.0"
  # s.osx.deployment_target = "10.7"
  # s.watchos.deployment_target = "2.0"
  # s.tvos.deployment_target = "9.0"


  # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Specify the location from where the source should be retrieved.
  #  Supports git, hg, bzr, svn and HTTP.
  #

  s.source       = { :git => "https://github.com/lilianmao/LLToast.git", :tag => "#{s.version}" }


  # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  CocoaPods is smart about how it includes source code. For source files
  #  giving a folder will include any swift, h, m, mm, c & cpp files.
  #  For header files it will include any header in the folder.
  #  Not including the public_header_files will make all headers public.
  #

  s.source_files  = "LLToast/*"
  #  s.exclude_files = "LLToast/*"

  # s.public_header_files = "Classes/**/*.h"


  # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  A list of resources included with the Pod. These are copied into the
  #  target bundle with a build phase script. Anything else will be cleaned.
  #  You can preserve files from being cleaned, please don't preserve
  #  non-essential files like tests, examples and documentation.
  #

  # s.resource  = "icon.png"
  # s.resources = "Resources/*.png"

  # s.preserve_paths = "FilesToSave", "MoreFilesToSave"


  # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  Link your library with frameworks, or libraries. Libraries do not include
  #  the lib prefix of their name.
  #

  # s.framework  = "SomeFramework"
  # s.frameworks = "SomeFramework", "AnotherFramework"

  # s.library   = "iconv"
  # s.libraries = "iconv", "xml2"


  # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
  #
  #  If your library depends on compiler flags you can set them in the xcconfig hash
  #  where they will only apply to your library. If you depend on other Podspecs
  #  you can include multiple dependencies to ensure it works.

  # s.requires_arc = true

  # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
  s.dependency "pop", "~> 1.0"

end

這里我介紹幾個要改的屬性:

我先強調一下這個文件如果你需要該屬性,必須去掉前面的#,不然是無效的,我被這個坑了好一會兒。(后來才知道這個ruby語言的注釋)

s.version 一般情況下改為1.0.0
s.description 寫一個對于你的框架代碼的簡單注釋
s.homepage 寫一個你項目對于的github主頁
s.license 我寫的是MIT(雖然我也沒懂為啥寫這個)
s.platform 我寫的是8.0的系統,可以默認,但是你得保持對于你寫的系統的兼容性。
s.source 這個必須指向你的github項目的地址
s.source_files 這里我已開始改錯了,前面有個#,應該是注釋的意思,你要把注釋去掉,然后寫上你的框架代碼的位置,這里我是當前文件夾->LLToast下面的所有文件。
s.dependency 你這個框架依賴的庫,我依賴了pop框架。

最后用一句代碼檢查你的pod有沒有問題(第二句代碼可以看到詳細錯誤)

pod lib lint
pod lib lint --verbose --no-clean

如果你看到passed invalidation的話,就說明你大功告成了。

如果你出了這個問題:

Encountered an unknown error (/usr/bin/xcrun simctl list -j devices)

說明沒有將Command Line Tools工具放到xcode中,詳見https://stackoverflow.com/questions/29108172/xcrun-unable-to-find-simctl

2.3.3 提交修改文件到github上

1,pod驗證

set the new version to 1.0.0
set the new tag to 1.0.0

2,將本地git倉庫更新到遠程的倉庫

git add .
git commit -m "release 1.0.0"
git tag '1.0.0'
git push --tags
git push origin master

這里我還遇到一個錯誤,git倉庫指向錯誤的倉庫,這個google上有解答的,用git remote --v查看,然后git set_url,具體可以google一下。

2.4將podspec文件跟新到CocoaPods官方倉庫

最后一步啦,小伙伴們,堅持一下。
2014年之前是需要向pod官方發pull request的,現在不要啦,我看的博客是2014之前的,所以得到的回復是

pod的官方回復

下面我會貼出來2014年之前的,大家可以了解一下過程,現在只需要幾行代碼就可以啦。下面是代碼和成功的界面。

pod trunk push LLToast.podspec
成功的界面

如果大家遇到下面這個問題

Encountered an unknown error (/usr/bin/xcrun simctl list -j devices)

原因可能有很多種,我的原因是是xcode沒有配置上Command Line Tools,詳見https://stackoverflow.com/questions/29108172/xcrun-unable-to-find-simctl

xcode配置Command Line Tools

附:2014年如何更新pod到官方倉庫

2.4.1 fork官方倉庫并clone下來

fork一份CocoaPods官方的Specs倉庫:傳送門
然后clone下來

https://github.com/lilianmao/Specs

2.4.2 將自己的podspec文件夾放到spec并更新遠程倉庫

我的文件夾目錄

然后更新遠程倉庫

git add. 
git commit -m "add Toast spec"
git push origin master

2.4.3 向官方發送pull request,等待通知。

3參考文章

https://guides.cocoapods.org/
http://blog.csdn.net/wzzvictory/article/details/20067595
http://www.lxweimin.com/p/89605e02bf18

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 229,963評論 6 542
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 99,348評論 3 429
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 178,083評論 0 383
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,706評論 1 317
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 72,442評論 6 412
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,802評論 1 328
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,795評論 3 446
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,983評論 0 290
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 49,542評論 1 335
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 41,287評論 3 358
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,486評論 1 374
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 39,030評論 5 363
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,710評論 3 348
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 35,116評論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,412評論 1 294
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 52,224評論 3 398
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 48,462評論 2 378

推薦閱讀更多精彩內容