CocoaPods私有庫配置筆記

前情提要

公司項(xiàng)目一直在用CocoaPods管理第三方包,自己也想著將項(xiàng)目中的公用模塊抽離出來獨(dú)立的包。所以研究了一下。

準(zhǔn)備工作

github創(chuàng)建私有庫 如testSpecs.git

pod repo add testSpecs https://github.com/qgg/testSpecs.git

github創(chuàng)建工具庫 如QGGImagePicker 注意創(chuàng)建的時(shí)候勾選開源協(xié)議
命令行創(chuàng)建模版工程
pod lib create QGGImagePicker

根據(jù)提示創(chuàng)建完成

XXXXXX$ pod lib create QGGImagePicker
Cloning `https://github.com/CocoaPods/pod-template.git` into `QGGImagePicker`.
Configuring QGGImagePicker 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?? [ ObjC / Swift ]
 > ObjC
Would you like to include a demo application with your library? [ Yes / No ]
 > Yes
Which testing frameworks will you use? [ Specta / Kiwi / None ]
 > None
Would you like to do view based testing? [ Yes / No ]
 > No
What is your class prefix?
 > QGG

完成后打開工程目錄如下:工具庫主要在紅框內(nèi)容Classes目錄下進(jìn)行開發(fā)


1.png

修改工程下的.podspec文件,如


# Be sure to run `pod lib lint QGGImagePicker.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             = "QGGImagePicker"
  s.version          = "0.0.1"
  s.summary          = "QGGImagePicker."

# 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
                        A ImagePicker Like WeChat's ImagePicker
                       DESC

  s.homepage         = "https://github.com/infiniteQin/QGGImagePicker.git"
  # s.screenshots     = "www.example.com/screenshots_1", "www.example.com/screenshots_2"
  s.license          = 'MIT'
  s.author           = { "changqin" => "changqin@ixiaopu.com" }
  s.source           = { :git => "https://github.com/infiniteQin/QGGImagePicker.git", :tag => s.version.to_s }
  # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

  s.platform     = :ios, '7.0'
  s.requires_arc = true

  s.source_files = 'Pod/Classes/**/*','Pod/Classes/**/**/*'
  #s.resource_bundles = {
  #  'QGGImagePicker' => ['Pod/Assets/*.png']
  #}
  #s.resources = "Pod/*.xcassets"

  # s.public_header_files = 'Pod/Classes/**/*.h'
  s.frameworks = "UIKit", "AssetsLibrary"
  s.dependency 'Masonry', '~> 0.6.3'
end

本地驗(yàn)證

pod lib lint 

驗(yàn)證成功后推送工程到github給如QGGImagePicker工具庫打tag(和podspec中的版本保持一致)

驗(yàn)證遠(yuǎn)程庫

pod spec lint

看到輸出如下內(nèi)容就成功了

QGGImagePicker.podspec passed validation.

私用庫中添加工具庫

pod repo push testSpecs QGGImgePicker.podspec

使用

pod search QGGImagePicker
Podfile文件添加 pod 'QGGImagePicker', '~> 0.0.1'
pod update --verbose --no-repo-update
注意這時(shí)候會(huì)報(bào)錯(cuò),解決辦法
pod spec lint --sources=‘https://github.com/qgg/testSpecs.git,https://github.com/CocoaPods/Specs'
或者
/.cocoapods/repos/testSpecs/下的內(nèi)容copy到/.cocoapods/repos/master/Specs下

支持****CocoaPods****公開庫

https://github.com/CocoaPods/Specs.git 下fork一份
將私有庫中的.podspec文件轉(zhuǎn)成.json

$ pod ipc spec QGGImagePicker.podspec >> QGGImagePicker.podspec.json

將內(nèi)容(目錄結(jié)構(gòu)如下)添加到CocoaPods/Specs提交待作者審核后即可

2.png

最后

分享幾篇我參考的文章
https://cocoapods.org/
http://www.cocoachina.com/ios/20150508/11785.html
http://www.cocoachina.com/ios/20150228/11206.html

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

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