四、遠(yuǎn)程私有庫(kù)的升級(jí)+依賴+分支+資源依賴+xx_prefix.pch

打造遠(yuǎn)程私有庫(kù)的步驟

一、遠(yuǎn)程私有庫(kù)的升級(jí)

  1. 首先把升級(jí)的源代碼拖到Classes文件夾里面
  2. 進(jìn)入到測(cè)試工程pod install安裝好測(cè)試代碼
$ cd /遠(yuǎn)程私有庫(kù)方案/RemoteLib/LRSoundBase2/Example 
$ pod install
  1. 將.spec文件里面的版本號(hào)進(jìn)行修改 , s.version = '0.2.0'
  2. 將本地私有庫(kù)所有文件提交到遠(yuǎn)程私有庫(kù)中
$ cd /遠(yuǎn)程私有庫(kù)方案/RemoteLib/LRSoundBase2 
$ git add .
$ git commit --m '增加了基礎(chǔ)配置和工具類'
$ git push origin master
  1. 根據(jù)描述文件的版本號(hào),打上對(duì)應(yīng)的tag值
$ git tag '0.2.0'
$ git push --tags
  1. 做好兩步驗(yàn)證,驗(yàn)證.spec文件的合法性
$ pod lib lint --allow-warnings
$ pod spec lint --allow-warnings
  1. 將.spec文件提交到本地的私有索引庫(kù)中,本地私有索引庫(kù)會(huì)自動(dòng)同步到遠(yuǎn)程私有索引庫(kù)中
$ pod repo push LRSoundSpec2 LRSoundBase2.podspec

8.回到宿主工程中,將podfile.lock刪除,使用pod install安裝最新pod庫(kù)

$ cd /遠(yuǎn)程私有庫(kù)方案/LRSound 
$ pod install

二、遠(yuǎn)程私有庫(kù)的升級(jí)+依賴

場(chǎng)景:我們?cè)谏?jí)私有庫(kù)的時(shí)候,有些時(shí)候可能會(huì)用到其他的第三方框架,這個(gè)時(shí)候我們一般會(huì)對(duì)第三方框架做一個(gè)二次封裝,那么我們?nèi)绻獙⒍畏庋b的代碼放到我們的私有庫(kù)當(dāng)中,我們就需要做依賴。

  1. 我們將要升級(jí)的代碼拖入到Classes文件夾下面
  2. 進(jìn)入到測(cè)試工程pod install安裝到測(cè)試代碼
  3. 需要將.spec文件做一個(gè)修改,主要是版本號(hào)和依賴關(guān)系
s.version = '0.3.0'
s.dependency 'AFNetworking'
  1. 提交本地代碼倉(cāng)庫(kù)到遠(yuǎn)程代碼倉(cāng)庫(kù),并且打上和描述文件一一對(duì)應(yīng)的tag值
  2. 做好兩步驗(yàn)證,上傳.spec文件到遠(yuǎn)程索引庫(kù)
  3. 回到宿主工程中,使用 pod update 或者 將podfile.lock刪除,使用pod install安裝最新pod庫(kù)

三、遠(yuǎn)程私有庫(kù)分支 + 依賴

  1. 我們檢查一下Classes文件夾下面的庫(kù)是否完整


    Classes
  2. 修改我們的spec文件sourc_files屬性,擴(kuò)展子庫(kù)的文件路徑,添加依賴,并且修改版本號(hào)

  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 ,否則會(huì)沖突
# s.source_files = 'LRSoundBase2/Classes/**/*'  
  1. 提交本地私有庫(kù)的代碼到遠(yuǎn)程私有庫(kù)中
  2. 對(duì)spec文件做好兩步驗(yàn)證
  3. 提交spec文件到本地索引庫(kù)和遠(yuǎn)程索引庫(kù)中
    如果在 pod repo push 時(shí)提示 The repo ’LRSoundSpec2’ at ‘/.cocoapods/repos/LRSoundSpec2‘ is not clean,解決辦法如下:
# 先提交一下遠(yuǎn)程私有庫(kù),再提交spec文件到本地索引庫(kù)和遠(yuǎn)程索引庫(kù)
$ cd /Users/admin/.cocoapods/repos/LRSoundSpec2
$ git add .
$ git commit --m 'xx'
$ git push
$ cd /遠(yuǎn)程私有庫(kù)分支/RemoteLib/LRSoundBase2
$ pod repo push LRSoundSpec2 LRSoundBase2.podspec
  1. 回到宿主工程中安裝所需要對(duì)應(yīng)的分支庫(kù)
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)程索引庫(kù)資源依賴

  1. 首先檢查源代碼的完整性
  2. 將源代碼扔到Classes文件夾下面
  3. 如果源代碼中有XIB這類型的資源,我們需要找到對(duì)應(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)程索引庫(kù)圖片依賴

  1. 首先檢查源代碼的完整性
  2. 將需要集成到私有庫(kù)的圖片資源扔到Assets文件夾下面,并且修改 spec 文件中的資源文件路徑,安裝到 Example 測(cè)試工程


    添加圖片資源到 Assets
 s.resource_bundles = {
   'LRSoundMain1' => ['LRSoundMain1/Assets/*.png']
 }

products -> LRSoundMain1_example.app -> show in finder -> 顯示包內(nèi)容 -> Assets.car (圖片資源文件)

  1. 其他需要使用的圖片資源還是放在測(cè)試工程中的圖片資源文件夾下面


    添加其他圖片到宿主工程
  2. 如果說(shuō)有使用到xib或者storyBoard的地方需要加載圖片,需要在使用圖片的地方指明存放圖片資源的bundle路徑。

products -> LRSoundMain1_example.app -> show in finder -> 顯示包內(nèi)容 -> Frameworks -> LRSoundMain1.framework -> LRSoundMain1.bundle

xib 圖片資源的路徑
  1. 在給控件設(shè)置圖片的位置,需要去指明圖片資源存放的bundle路徑,圖片的類型以及分辨率都要指明,否則圖片加載不了。
    //不在 mainBundle 里面加載圖片,必須添加后綴名和分辨率,否則加載不出來(lái)
    NSBundle *currentBuddle = [NSBundle bundleForClass:[self class]];
    NSString *imagePath = [currentBuddle pathForResource:@"tabbar_bg@2x.png" ofType:nil inDirectory:@"LRSoundMain1.bundle"];
    UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
  1. 修改 spec 文件,提交spec文件到本地索引庫(kù)和遠(yuǎn)程索引庫(kù)中

  2. 回到宿主工程中安裝所需要對(duì)應(yīng)的分支庫(kù)

六、設(shè)置框架中 xx-prefix.pch 文件,導(dǎo)入公共頭文件,通過(guò)修改 spec 文件中的prefix_header_contents屬性

s.prefix_header_contents = '#import "const.h"','#import "macro.h"'
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容