iOS框架如何發(fā)布到CocoaPods

前言

經(jīng)常使用別人的封裝庫或者項(xiàng)目,在項(xiàng)目開發(fā)中自己也有封裝,即使不能給別人廣泛使用,也可以自己在多項(xiàng)目中pod方式使用自己封裝的代碼
前提:mac上已經(jīng)裝好了pod,git

一、創(chuàng)建自己庫添加Cocoapods支持

1、基于pod自動創(chuàng)建項(xiàng)目

在終端輸入

pod lib create JGCache

提示對應(yīng)的詢問命令

Cloning `https://github.com/CocoaPods/pod-template.git` into `JGCache`.
Configuring JGCache template.

------------------------------

To get you started we need to ask a few questions, this should only take a minute.

If this is your first time we recommend running through with the guide: 
 - http://guides.cocoapods.org/making/using-pod-lib-create.html
 ( hold cmd and double click links to open in a browser. )


What language do you want to use?? [ Swift / ObjC ]
 > Swift

Would you like to include a demo application with your library? [ Yes / No ]
 > Yes

Which testing frameworks will you use? [ Quick / None ]
 > None

Would you like to do view based testing? [ Yes / No ]
 > No

項(xiàng)目創(chuàng)建成功,并編譯成功

2、接下來在https://github.com/官網(wǎng)自己的賬號下創(chuàng)建一個倉庫JGCache(這里不是重點(diǎn),不用介紹了)

3、將pod命令自動創(chuàng)建的項(xiàng)目上傳到github JGCache項(xiàng)目中,(這里不是重點(diǎn),不用介紹了)

4、給倉庫JGCache 主分支master 創(chuàng)建一個tag 0.1.0 (這里不是重點(diǎn),不用介紹了)

5、打開項(xiàng)目中的JGCache.podspec文件可以看到默認(rèn)設(shè)置

#
# Be sure to run `pod lib lint JGCache.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#

Pod::Spec.new do |s|
  s.name             = 'JGCache'
  s.version          = '0.1.0'
  s.summary          = 'A short description of JGCache.'

# 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
TODO: Add long description of the pod here.
                       DESC

  s.homepage         = 'https://github.com/lbj147123@163.com/JGCache'
  # s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { 'lbj147123@163.com' => 'lbj147123@163.com' }
  s.source           = { :git => 'https://github.com/lbj147123@163.com/JGCache.git', :tag => s.version.to_s }
  # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

  s.ios.deployment_target = '8.0'

  s.source_files = 'JGCache/Classes/**/*'
  
  # s.resource_bundles = {
  #   'JGCache' => ['JGCache/Assets/*.png']
  # }

  # s.public_header_files = 'Pod/Classes/**/*.h'
  # s.frameworks = 'UIKit', 'MapKit'
  # s.dependency 'AFNetworking', '~> 2.3'
end

6、修改項(xiàng)目中的JGCache.podspec文件的設(shè)置為(這里就不介紹每一項(xiàng)的意思了)

Pod::Spec.new do |s|
  s.name             = 'JGCache'
  s.version          = '0.1.0'
  s.summary          = 'this is description'

# 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
TODO: this is description
                       DESC

  s.homepage         = 'https://github.com/Ucself/JGCache'
  # s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { '李保君' => 'lbj147123@163.com' }
  s.source           = { :git => 'https://github.com/Ucself/JGCache.git', :tag => s.version.to_s }
  # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

  s.ios.deployment_target = '8.0'

  s.source_files = 'JGCache/Classes/**/*'
  
  # s.resource_bundles = {
  #   'JGCache' => ['JGCache/Assets/*.png']
  # }

  # s.public_header_files = 'Pod/Classes/**/*.h'
  # s.frameworks = 'UIKit', 'MapKit'
  s.dependency 'ObjectMapper', '~> 3.0.0'
end

7、檢測填寫的podspec是否有錯誤,cd進(jìn)入JGCache文件目錄

pod spec lint

8、測試本地導(dǎo)入的文件是否報(bào)錯。cd 進(jìn)入項(xiàng)目Example文件路徑,導(dǎo)入依賴的第三方庫

pod install 

9、上傳的cocopods管理

pod trunk push JGCache.podspec --allow-warnings

二、更新自己庫添加Cocoapods支持

1、JGCache.podspec 文件中你需要更改的項(xiàng)目更改(主要更改版本如:1.0.0)

2、在啊gitbug對你的工程添加標(biāo)簽如1.0.0

3、上傳工程工程代碼

4、再次執(zhí)行

pod trunk push JGCache.podspec --allow-warnings
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容