打造遠程私有庫的步驟
一、遠程私有庫的升級
- 首先把升級的源代碼拖到Classes文件夾里面
- 進入到測試工程pod install安裝好測試代碼
$ cd /遠程私有庫方案/RemoteLib/LRSoundBase2/Example
$ pod install
- 將.spec文件里面的版本號進行修改 ,
s.version = '0.2.0'
- 將本地私有庫所有文件提交到遠程私有庫中
$ cd /遠程私有庫方案/RemoteLib/LRSoundBase2
$ git add .
$ git commit --m '增加了基礎配置和工具類'
$ git push origin master
- 根據描述文件的版本號,打上對應的tag值
$ git tag '0.2.0'
$ git push --tags
- 做好兩步驗證,驗證.spec文件的合法性
$ pod lib lint --allow-warnings
$ pod spec lint --allow-warnings
- 將.spec文件提交到本地的私有索引庫中,本地私有索引庫會自動同步到遠程私有索引庫中
$ pod repo push LRSoundSpec2 LRSoundBase2.podspec
8.回到宿主工程中,將podfile.lock刪除,使用pod install安裝最新pod庫
$ cd /遠程私有庫方案/LRSound
$ pod install
二、遠程私有庫的升級+依賴
場景:我們在升級私有庫的時候,有些時候可能會用到其他的第三方框架,這個時候我們一般會對第三方框架做一個二次封裝,那么我們如果要將二次封裝的代碼放到我們的私有庫當中,我們就需要做依賴。
- 我們將要升級的代碼拖入到Classes文件夾下面
- 進入到測試工程pod install安裝到測試代碼
- 需要將.spec文件做一個修改,主要是版本號和依賴關系
s.version = '0.3.0'
s.dependency 'AFNetworking'
- 提交本地代碼倉庫到遠程代碼倉庫,并且打上和描述文件一一對應的tag值
- 做好兩步驗證,上傳.spec文件到遠程索引庫
- 回到宿主工程中,使用
pod update
或者將podfile.lock刪除,使用pod install安裝最新pod庫
三、遠程私有庫分支 + 依賴
-
我們檢查一下Classes文件夾下面的庫是否完整
Classes 修改我們的spec文件sourc_files屬性,擴展子庫的文件路徑,添加依賴,并且修改版本號
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/**/*'
- 提交本地私有庫的代碼到遠程私有庫中
- 對spec文件做好兩步驗證
- 提交spec文件到本地索引庫和遠程索引庫中
如果在pod repo push
時提示The repo ’LRSoundSpec2’ at ‘/.cocoapods/repos/LRSoundSpec2‘ is not clean
,解決辦法如下:
# 先提交一下遠程私有庫,再提交spec文件到本地索引庫和遠程索引庫
$ cd /Users/admin/.cocoapods/repos/LRSoundSpec2
$ git add .
$ git commit --m 'xx'
$ git push
$ cd /遠程私有庫分支/RemoteLib/LRSoundBase2
$ pod repo push LRSoundSpec2 LRSoundBase2.podspec
- 回到宿主工程中安裝所需要對應的分支庫
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
四、遠程索引庫資源依賴
- 首先檢查源代碼的完整性
- 將源代碼扔到Classes文件夾下面
- 如果源代碼中有XIB這類型的資源,我們需要找到對應的bundle路徑,重新指明bundle路徑,修改之前使用的mainBundle路徑。
加載 Xib 文件:
+ (instancetype)middleView {
NSBundle *currentBundle = [NSBundle bundleForClass:[self class]];
TZMiddleView *middleView = [[currentBundle loadNibNamed:@"TZMiddleView" owner:nil options:nil] firstObject];
return middleView;
}
五、遠程索引庫圖片依賴
- 首先檢查源代碼的完整性
-
將需要集成到私有庫的圖片資源扔到Assets文件夾下面,并且修改 spec 文件中的資源文件路徑,安裝到 Example 測試工程
添加圖片資源到 Assets
s.resource_bundles = {
'LRSoundMain1' => ['LRSoundMain1/Assets/*.png']
}
products -> LRSoundMain1_example.app -> show in finder -> 顯示包內容 -> Assets.car (圖片資源文件)
-
其他需要使用的圖片資源還是放在測試工程中的圖片資源文件夾下面
添加其他圖片到宿主工程 如果說有使用到xib或者storyBoard的地方需要加載圖片,需要在使用圖片的地方指明存放圖片資源的bundle路徑。
products -> LRSoundMain1_example.app -> show in finder -> 顯示包內容 -> Frameworks -> LRSoundMain1.framework -> LRSoundMain1.bundle
xib 圖片資源的路徑
- 在給控件設置圖片的位置,需要去指明圖片資源存放的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文件到本地索引庫和遠程索引庫中
回到宿主工程中安裝所需要對應的分支庫
六、設置框架中 xx-prefix.pch 文件,導入公共頭文件,通過修改 spec 文件中的prefix_header_contents屬性
s.prefix_header_contents = '#import "const.h"','#import "macro.h"'