前提條件
pod環(huán)境
代碼倉庫
倉庫以Coding為例,建立團隊什么按下不表。
1.配置sshKey
2.新建項目
3.新建索引倉庫
4.新建庫/代碼倉庫
5.搭建本地的私有索引庫
首先把剛剛新建的私有庫克隆到本地
git clone https://e.coding.net/livermorecoding/liver/LiverSpec.git
(地址換成自己的,記住是存放索引這個)
添加本地索引庫
pod repo add LiverSpec https://e.coding.net/livermorecoding/liver/LiverSpec.git
(LiverSpec 為 repo的名,如CocoaPods自帶的master)
查看是否添加成功了
pod repo
可以查看到剛剛我們添加的LiverSpec索引庫了
LiverSpec
Type: git (master)
URL: https://e.coding.net/livermorecoding/liver/LiverSpec.git
Path: /Users/zhanghuan/.cocoapods/repos/LiverSpec
6.搭建Pod私有庫所需要的項目工程
先克隆倉庫到本地
git clone https://e.coding.net/livermorecoding/liver/LiverLib.git
(地址換成自己的,記住是存放自己想要存放pod引用文件的這個庫)
再自己找一個目錄,通過CocoPods的官方命令創(chuàng)建Pod項目工程
以我為例,cd 到podlib目錄
執(zhí)行以下命令
pod lib create LiverLib
(LiverLib為工程名字)
其中prefix是文件的前綴,你可以通過打開Example目錄查看其中的類文件,你會發(fā)現(xiàn)所有的類都加上了這個前綴,如AppDelegate變成了LIVERAppDelegate。
初始化完成后會自動打開工程。
6.替換文件
打開LiverLib-> Classes 目錄,把ReplaceMe.m文件替換成你想要pod引用的文件,可以是一個framework,或者.h.m.a等文件。
例如我在這里存放了兩個基類
7. 修改.podspec
Pod::Spec.new do |s|
s.name = 'LiverLib'
s.version = '0.1.0'
s.summary = 'description of LiverLib.'
?
# 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
# homepage要有效
s.homepage = 'https://www.baidu.com'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'zh' => '949077140@qq.com' }
# source是之前要做的pod的引用庫地址
s.source = { :git => 'https://e.coding.net/livermorecoding/liver/LiverLib.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
?
s.ios.deployment_target = '9.0'
?
s.source_files = 'LiverLib/Classes/**/*'
8.校驗LiverLib.podspec 是否有效
pod lib lint LiverLib.podspec --sources=https://cdn.cocoapods.org/,https://e.coding.net/livermorecoding/liver/LiverSpec.git
這里需要添加--sources,指明校驗的源為自己的spec索引庫
9. 關(guān)聯(lián)遠程倉庫
把通過pod lib create 建立的模板工程的.git 文件替換為第四部創(chuàng)建的自己使用的pod引用庫.git文件,目的在于關(guān)聯(lián)當前的項目到私有庫。
我這里是podlib下的LiverLib工程.git 替換為與podlib同級的LiverLib下的.git文件。
10. 提交工程,打tag
cd到模板工程,提交代碼,并打tag,注意版本的一致性,git tag 版本和LiverLib.podspec中的版本一致
git add --all
git commit -m"工程提交"
git push
git tag "0.1.0"
git push --tags
結(jié)果查看
11.添加自己的spec source
pod repo add LiverSpec https://e.coding.net/livermorecoding/liver/LiverSpec.git
LiverSpec為pod repo 查看到的我們自己新建的repo名稱,后面地址為私有的spec倉庫
12. 把本地的私有庫推送到遠程
pod repo push LiverSpec LiverLib.podspec --sources=https://cdn.cocoapods.org/,https://e.coding.net/livermorecoding/liver/LiverSpec.git
查看效果
12.驗證一把
方式一:
pod search LiverLib
方式二:
新建工程,修改podfile文件
source 'https://cdn.cocoapods.org'
source 'https://e.coding.net/livermorecoding/liver/LiverSpec.git'
?
use_frameworks!
?
platform :ios, '10.0'
target 'PodApp' do
pod 'LiverLib', '0.1.0'
?
end
pod install