創(chuàng)建Cocoapods私人倉庫

之前有一篇介紹了怎么創(chuàng)建私人項(xiàng)目手把手教你創(chuàng)建podspec,創(chuàng)建成功之后進(jìn)行發(fā)布。最終發(fā)布
到Cocoapods官方倉庫中。但是有時(shí)候我們創(chuàng)建完自己的pod項(xiàng)目之后,并不想公開發(fā)布,只限于自己或者公司使用,這時(shí)候就需要我們創(chuàng)建自己的私人倉庫,將pod項(xiàng)目發(fā)布到自己的私人倉庫中。

創(chuàng)建一個(gè)git私人項(xiàng)目

由于github只能創(chuàng)建公開項(xiàng)目,如果要?jiǎng)?chuàng)建私人項(xiàng)目是要花錢的,所以我這邊使用的是碼市,免費(fèi)最多能
創(chuàng)建5個(gè)私人項(xiàng)目,挺不錯(cuò)的。這個(gè)私人項(xiàng)目是我們用來存儲spec的總倉庫

創(chuàng)建podspec

  • 創(chuàng)建spec工程

pod lib create [名稱]

這個(gè)與pod spec create的區(qū)別其實(shí)就是幫我們拉了一個(gè)模板,確實(shí)能省很多事情,里邊包括了一個(gè)Example工程

  • 再創(chuàng)建一個(gè)git私人項(xiàng)目

這個(gè)是用來存放我們Xcode工程和代碼的。說白了就是托管我們代碼的地方,主要是用來配飾spec中s.source用的

  • 將我們要公開的代碼和Example提交到git倉庫

在第一步我們創(chuàng)建的工程中執(zhí)行

git add .

git commit -m 'init'

git remote add orgin [剛才我們創(chuàng)建倉庫的地址]

git push origin master

到這里為止已經(jīng)將我們的代碼提交到剛才創(chuàng)建的代碼倉庫中了。(如果沒有權(quán)限則要配置.ssh中公鑰私鑰)
由于spec文件的原因我們其實(shí)還有一步?jīng)]有做,其實(shí)就是打tag,只有打了tag才行,:tag => s.version.to_s就是這句話用到的
接下來我們繼續(xù)打tag

git tag 0.1.0

git push --tags

編寫xx.podspec文件

#
# Be sure to run `pod lib lint Utils.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             = 'Utils'
  s.version          = '0.1.0'
  s.summary          = 'Utils.'

# 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
Utils封裝常用組件
                       DESC

  s.homepage         = 'https://coding.net/u/FlyOceanFish/p/Utils'
  # s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { 'FlyOceanFish' => '978456068@126.com' }
  s.source           = { :git => 'https://git.coding.net/FlyOceanFish/Utils.git', :tag => s.version.to_s }
  # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

  s.ios.deployment_target = '8.0'

  s.source_files = 'Utils/Classes/**/*'

  # s.resource_bundles = {
  #   'Utils' => ['Utils/Assets/*.png']
  # }

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

這個(gè)是我寫的,也可以參考我之前的一篇文章

檢驗(yàn)spec文件的合法性

pod spec lint

如果有什么錯(cuò)誤,可以參照提示修改就行了

發(fā)布我們的podspec文件到我們的私人倉庫

  • 首先添加私人倉庫源

這個(gè)私人倉庫源其實(shí)就是我們第一步創(chuàng)建的那個(gè)倉庫地址

pod repo

這個(gè)命令可以看到我們目前的私人倉庫源

pod repo add [倉庫源名稱][倉庫地址]

比如:

pod repo add FlyOceanSpecs https://git.coding.net/FlyOceanFish/FlyOceanSpecs.git

倉庫源隨便起名字,不過這個(gè)我們發(fā)布我們的spec項(xiàng)目的時(shí)候用的到。倉庫地址就是我們
第一步創(chuàng)建的那個(gè)git倉庫地址

  • 發(fā)布到私人倉庫

接上一步我們的FlyOceanSpecs倉庫源

pod repo push FlyOceanSpecs Utils.podspec

使用

我的Podfile文件如下:

# Uncomment the next line to define a global platform for your project
 platform :ios, '9.0'
 source 'https://git.coding.net/FlyOceanFish/FlyOceanSpecs.git'
 source 'https://github.com/CocoaPods/Specs.git'
target 'test' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
   use_frameworks!
  pod 'YTOBaiduMapKit'
  # Pods for test

end

這就可以正常使用了

總結(jié)

這個(gè)過程其實(shí)還是挺復(fù)雜的,大家如果有什么問題可以給我留言,我會及時(shí)回復(fù)的

注:
以上是我制作的一個(gè)YTOBaiduMapKit,由于百度api針對pod導(dǎo)入只支持全量導(dǎo)入,這樣則會導(dǎo)致整個(gè)包比較大,所以我制作了一個(gè)閹割版,只包括了BaiduMapAPI_Base、BaiduMapAPI_Location、BaiduMapAPI_Map這三個(gè)包就是百度基礎(chǔ)功能和定位的功能

最后編輯于
?著作權(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)容