cocoaPods 私有倉庫的創建和使用
一、創建遠程的POD 倉庫
直接在git上創建一個空的pod倉庫即可,
執行
pod repo add #倉庫名字# 倉庫地址
自動會將遠程私有倉庫clone到 /Users/用戶名/.cocoapods/repos 目錄下。
自此 遠程倉庫已經準備好了。
二、創建本地的組件
使用命令
pod lib create [pod name]
會自動創建一個本地的庫,我們可以在這裏開發我們的組件庫。
這裏最主要的是NAME.podspec 這個文件的配置 類似如下
#
# Be sure to run `pod lib lint AUExtension.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 https://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'Extension'
s.version = '0.1.9' # 版本號,這個版本號一定要和tag號一致,需要先打tag,
s.summary = 'A short description of AUExtension.'
# 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 = 'http://gitlab..net'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'ericdream' => '[email protected]' }
s.source = { :git => '你的代碼倉庫地址', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.ios.deployment_target = '8.0'
s.source_files = 'Extension/Classes/Extension.h'
s.subspec 'MiscExtend' do |ss|
ss.source_files = 'Extension/Classes/MiscExtend/**/*.{h,m}'
end
s.subspec 'Extend' do |ss|
ss.source_files = 'Extension/Classes/UIExtend/**/*.{h,m}'
ss.dependency 'Extension/MiscExtend'
mrcFiles = 'Extension/Classes/UIExtend/**/UIViewController+ExchageDeallocFunction.{h,m}'
ss.exclude_files = mrcFiles
ss.subspec 'MRC' do |sp|
sp.source_files = mrcFiles
sp.requires_arc = false
end
end
# s.resource_bundles = {
# 'Extension' => ['Extension/Assets/*.png']
# }
# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
# s.dependency 'AFNetworking', '~> 2.3'
end
version: 組件的版本號,必須和tag 號保持一致
source_files :資源的路徑,
exclude_fies : 忽略的資源文件,不包含
requires_arc : 是否開啓arc 默認開啓arc
public_header_files :頭文件
frameworks: 需要的frameworks
libraries :所有的libraries,注意:需要去掉前綴 lib,如:s.libraries=‘z.1.2.5’ (依賴庫:libz.1.2.5)
dependency: 需要的依賴
特別注意,cocoapod中沒有文件目錄的概念,只有子組件的概念,如果沒有子組件,所有的文件都在同一級目錄下,要’分目錄’就要建立子組件。每一個子組件就是一個目錄。子組件之間相互依賴調用的時候需要依賴被調用的組件。
配置文件修改完成之後,可以提交代碼到遠端,並打一個tag,tag和 配置文件中的s.version 保持一致。
三、驗證並把cocoaPods 配置文件推送到遠端倉庫
配置文件寫完成之後我們需要驗證配置文件的正確性。那麼如何驗證呢。
通過命令:pod lib lint name.podspec --use-libraries --allow-warnings --verbose
後邊參數可以去掉,建議加上,第一個參數不加可能不會通過驗證,不忽略警公告也不會驗證通過,
驗證通過之後我們就可以把配置文件推送的pod遠端倉庫:
pod repo push 倉庫名 配置文件.podspec --sources='自己倉庫地址,https://github.com/CocoaPods/Specs.git' --use-libraries --allow-warnings --verbose
如果你的組件不依賴私有組件可以去電自己的pod私有倉庫地址。
執行這條命令之後,系統會自動的在 /Users/用戶名/.cocoapods/repos 目錄下 創建一個和版本號同名的目錄,並把配置文件copy進來,然後在另外的一個目錄下創建工作空間,並編譯你的組件,編譯通過之後才真正的把配置文件提交到pod倉庫。
自此pod 庫完成製作。
四、使用
要使用我們自己自作的私有倉庫首先你需要在 profile 文件中添加上你的倉庫源地址:
如:source 'http://gitlab........respos.git'
然後再添加倉庫:
pod '組件名'
pod 版本共控制
pod ‘組件’, ‘1.0’ # 指定版本
‘> 0.1’ 0.1 以上
‘>= 0.1’ 大於等於 0.1
‘< 0.1’ 小於0.1
‘<= 0.1’ 小於等於0.1
‘~> 0.1.2’ # 0.1 以上,0.2 一下
‘~>0.1’ # 0.1以上 1.0 一下
最後只需要執行命令:
pod install
完成。