打造遠(yuǎn)程私有庫的步驟
一滞诺、遠(yuǎn)程私有庫的升級
- 首先把升級的源代碼拖到Classes文件夾里面
- 進(jìn)入到測試工程pod install安裝好測試代碼
$ cd /遠(yuǎn)程私有庫方案/RemoteLib/LRSoundBase2/Example
$ pod install
- 將.spec文件里面的版本號進(jìn)行修改 ,
s.version = '0.2.0'
- 將本地私有庫所有文件提交到遠(yuǎn)程私有庫中
$ cd /遠(yuǎn)程私有庫方案/RemoteLib/LRSoundBase2
$ git add .
$ git commit --m '增加了基礎(chǔ)配置和工具類'
$ git push origin master
- 根據(jù)描述文件的版本號吨悍,打上對應(yīng)的tag值
$ git tag '0.2.0'
$ git push --tags
- 做好兩步驗(yàn)證胚想,驗(yàn)證.spec文件的合法性
$ pod lib lint --allow-warnings
$ pod spec lint --allow-warnings
- 將.spec文件提交到本地的私有索引庫中尼啡,本地私有索引庫會自動同步到遠(yuǎn)程私有索引庫中
$ pod repo push LRSoundSpec2 LRSoundBase2.podspec
8.回到宿主工程中暂衡,將podfile.lock刪除,使用pod install安裝最新pod庫
$ cd /遠(yuǎn)程私有庫方案/LRSound
$ pod install
二崖瞭、遠(yuǎn)程私有庫的升級+依賴
場景:我們在升級私有庫的時候狂巢,有些時候可能會用到其他的第三方框架,這個時候我們一般會對第三方框架做一個二次封裝书聚,那么我們?nèi)绻獙⒍畏庋b的代碼放到我們的私有庫當(dāng)中唧领,我們就需要做依賴藻雌。
- 我們將要升級的代碼拖入到Classes文件夾下面
- 進(jìn)入到測試工程pod install安裝到測試代碼
- 需要將.spec文件做一個修改,主要是版本號和依賴關(guān)系
s.version = '0.3.0'
s.dependency 'AFNetworking'
- 提交本地代碼倉庫到遠(yuǎn)程代碼倉庫斩个,并且打上和描述文件一一對應(yīng)的tag值
- 做好兩步驗(yàn)證胯杭,上傳.spec文件到遠(yuǎn)程索引庫
- 回到宿主工程中,使用
pod update
或者將podfile.lock刪除受啥,使用pod install安裝最新pod庫
三歉摧、遠(yuǎn)程私有庫分支 + 依賴
-
我們檢查一下Classes文件夾下面的庫是否完整
Classes 修改我們的spec文件sourc_files屬性,擴(kuò)展子庫的文件路徑腔呜,添加依賴叁温,并且修改版本號
s.version = '0.4.0'
s.subspec 'Category' do |c|
c.source_files = 'LRSoundBase2/Classes/Category/**/*'
end
s.subspec 'Network' do |n|
n.source_files = 'LRSoundBase2/Classes/Network/**/*'
n.dependency 'AFNetworking' #將依賴添加到分支上
end
s.subspec 'Tool' do |t|
t.source_files = 'LRSoundBase2/Classes/Tool/**/*'
end
# 需要注釋掉 s.source_files ,否則會沖突
# s.source_files = 'LRSoundBase2/Classes/**/*'
- 提交本地私有庫的代碼到遠(yuǎn)程私有庫中
- 對spec文件做好兩步驗(yàn)證
- 提交spec文件到本地索引庫和遠(yuǎn)程索引庫中
如果在pod repo push
時提示The repo ’LRSoundSpec2’ at ‘/.cocoapods/repos/LRSoundSpec2‘ is not clean
核畴,解決辦法如下:
# 先提交一下遠(yuǎn)程私有庫膝但,再提交spec文件到本地索引庫和遠(yuǎn)程索引庫
$ cd /Users/admin/.cocoapods/repos/LRSoundSpec2
$ git add .
$ git commit --m 'xx'
$ git push
$ cd /遠(yuǎn)程私有庫分支/RemoteLib/LRSoundBase2
$ pod repo push LRSoundSpec2 LRSoundBase2.podspec
- 回到宿主工程中安裝所需要對應(yīng)的分支庫
source 'https://gitee.com/lrskey/LRSoundSpec2.git'
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
target 'LRSound' do
use_frameworks!
pod 'LRSoundBase2/Tool'
pod 'LRSoundBase2/Network'
end
四、遠(yuǎn)程索引庫資源依賴
- 首先檢查源代碼的完整性
- 將源代碼扔到Classes文件夾下面
- 如果源代碼中有XIB這類型的資源谤草,我們需要找到對應(yīng)的bundle路徑跟束,重新指明bundle路徑,修改之前使用的mainBundle路徑丑孩。
加載 Xib 文件:
+ (instancetype)middleView {
NSBundle *currentBundle = [NSBundle bundleForClass:[self class]];
TZMiddleView *middleView = [[currentBundle loadNibNamed:@"TZMiddleView" owner:nil options:nil] firstObject];
return middleView;
}
五冀宴、遠(yuǎn)程索引庫圖片依賴
- 首先檢查源代碼的完整性
-
將需要集成到私有庫的圖片資源扔到Assets文件夾下面,并且修改 spec 文件中的資源文件路徑温学,安裝到 Example 測試工程
添加圖片資源到 Assets
s.resource_bundles = {
'LRSoundMain1' => ['LRSoundMain1/Assets/*.png']
}
products -> LRSoundMain1_example.app -> show in finder -> 顯示包內(nèi)容 -> Assets.car (圖片資源文件)
-
其他需要使用的圖片資源還是放在測試工程中的圖片資源文件夾下面
添加其他圖片到宿主工程 如果說有使用到xib或者storyBoard的地方需要加載圖片略贮,需要在使用圖片的地方指明存放圖片資源的bundle路徑。
products -> LRSoundMain1_example.app -> show in finder -> 顯示包內(nèi)容 -> Frameworks -> LRSoundMain1.framework -> LRSoundMain1.bundle
xib 圖片資源的路徑
- 在給控件設(shè)置圖片的位置仗岖,需要去指明圖片資源存放的bundle路徑逃延,圖片的類型以及分辨率都要指明,否則圖片加載不了轧拄。
//不在 mainBundle 里面加載圖片揽祥,必須添加后綴名和分辨率,否則加載不出來
NSBundle *currentBuddle = [NSBundle bundleForClass:[self class]];
NSString *imagePath = [currentBuddle pathForResource:@"tabbar_bg@2x.png" ofType:nil inDirectory:@"LRSoundMain1.bundle"];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
修改 spec 文件檩电,提交spec文件到本地索引庫和遠(yuǎn)程索引庫中
回到宿主工程中安裝所需要對應(yīng)的分支庫
六拄丰、設(shè)置框架中 xx-prefix.pch 文件,導(dǎo)入公共頭文件俐末,通過修改 spec 文件中的prefix_header_contents屬性
s.prefix_header_contents = '#import "const.h"','#import "macro.h"'