MWPhotoBrowser 更新其依賴的第三方庫

前因

項(xiàng)目里面用到了環(huán)信的 EaseUI 庫,而其中又包含了第三方庫的引用。MWPhotoBrowser 就是其中的一個(gè)。而 MWPhotoBrowser 自身又包含了第三方的依賴,而且上次更新已經(jīng)很早了。作者不維護(hù)了。

MWPhotoBrowser 依賴的第三方庫:

  • MBProgressHUD
    • 0.9 (最新:1.0.0)
  • SDWebImage
    • 3.7 (最新:4.0.0)
  • DACircularProgress
    • 2.3 (最新:2.3.1)

尤其是 SDWebImage 這么大眾的的庫,竟然沒有更新。不能忍。于是就想著 fork 后,更新下依賴,自用。

本文的內(nèi)容,大體上是這次更新中遇到的問題的總結(jié)。

修改源文件

fork 后,MWPhotoBrowser 會(huì)在自己的 github 項(xiàng)目下。

git clone 下來。

修改 MWPhotoBrowser.podspec 文件

主要修改三個(gè)地方:

  • s.homepage (項(xiàng)目首頁地址)
  • s.source(項(xiàng)目源地址)
  • s.dependency (項(xiàng)目依賴的第三方庫,我們主要改動(dòng)的是這里)

修改的內(nèi)容如下 (可飄過)

Pod::Spec.new do |s|

  s.name = 'MWPhotoBrowser'
  s.version = '2.1.2'
  s.license = 'MIT'
  s.summary = 'A simple iOS photo and video browser with optional grid view, captions and selections.'
  s.description = <<-DESCRIPTION
                  MWPhotoBrowser can display one or more images or videos by providing either UIImage
                  objects, PHAsset objects, or URLs to library assets, web images/videos or local files.
                  The photo browser handles the downloading and caching of photos from the web seamlessly.
                  Photos can be zoomed and panned, and optional (customisable) captions can be displayed.
                  DESCRIPTION
  s.screenshots = [
    'https://raw.github.com/mwaterfall/MWPhotoBrowser/master/Screenshots/MWPhotoBrowser1.png',
    'https://raw.github.com/mwaterfall/MWPhotoBrowser/master/Screenshots/MWPhotoBrowser2.png',
    'https://raw.github.com/mwaterfall/MWPhotoBrowser/master/Screenshots/MWPhotoBrowser3.png',
    'https://raw.github.com/mwaterfall/MWPhotoBrowser/master/Screenshots/MWPhotoBrowser4.png',
    'https://raw.github.com/mwaterfall/MWPhotoBrowser/master/Screenshots/MWPhotoBrowser5.png',
    'https://raw.github.com/mwaterfall/MWPhotoBrowser/master/Screenshots/MWPhotoBrowser6.png'
  ]

 //修改這里
  s.homepage = 'https://github.com/EvoIos/MWPhotoBrowser'
  s.author = { 'Michael Waterfall' => 'michaelwaterfall@gmail.com' }
  s.social_media_url = 'https://twitter.com/mwaterfall'
 //修改這里
  s.source = {
    :git => 'https://github.com/EvoIos/MWPhotoBrowser.git',
    :tag => '2.1.2'
  }
  s.platform = :ios, '7.0'
  s.source_files = 'Pod/Classes/**/*'
  s.resource_bundles = {
    'MWPhotoBrowser' => ['Pod/Assets/*.png']
  }
  s.requires_arc = true

  s.frameworks = 'ImageIO', 'QuartzCore', 'AssetsLibrary', 'MediaPlayer'
  s.weak_frameworks = 'Photos'
 
 //修改這里
  s.dependency 'MBProgressHUD', '~> 1.0'
  s.dependency 'DACircularProgress', '~> 2.3.1'

  # SDWebImage
  s.dependency 'SDWebImage', '~> 4.0.0'

end

修改 MWPhoto.h

因?yàn)樾屡f版本語法的不同,所以需要手動(dòng)更改源項(xiàng)目的文件。目前,只有 SDWebImage 相關(guān)的需要修改。

頭文件引入 SDWebImage/SDWebImageDownloader.h

修改 downloadImageWithURL 方法,因?yàn)榕f版和新版的方法不一樣了,所以這里需要更改下。

// Load from local file
- (void)_performLoadUnderlyingImageAndNotifyWithWebURL:(NSURL *)url {
    @try {
        [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:url options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
            if (expectedSize > 0) {
                float progress = receivedSize / (float)expectedSize;
                NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:
                                      [NSNumber numberWithFloat:progress], @"progress",
                                      self, @"photo", nil];
                [[NSNotificationCenter defaultCenter] postNotificationName:MWPHOTO_PROGRESS_NOTIFICATION object:dict];
            }
        } completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
            if (error) {
                MWLog(@"SDWebImage failed to download image: %@", error);
            }
            _webImageOperation = nil;
            self.underlyingImage = image;
            dispatch_async(dispatch_get_main_queue(), ^{
                [self imageLoadingComplete];
            });

        }];
    } @catch (NSException *e) {
        MWLog(@"Photo from web: %@", e);
        _webImageOperation = nil;
        [self imageLoadingComplete];
    }
}

提交

更改完后,提交到 GitHub 上。然后就可以用了。

使用

使用的時(shí)候,有些不同。因?yàn)槲覀兪?fork 別人的庫,自己修改了,所以,不好傳到 pods 上公開使用。但是我們還想要使用改過的庫,怎么辦?

集成的時(shí)候,標(biāo)定遠(yuǎn)程項(xiàng)目庫的地址和 commit 的版本。至于為什么要有 commit 版本,stackOverflow 上有個(gè)提問,見這里。

最后 Podfile 里的文件內(nèi)容如下:

pod "MWPhotoBrowser", :git => 'https://github.com/EvoIos/MWPhotoBrowser.git', :commit => 'de697e101195557ddca85661ebb266fd3f10776c'

附錄

fork 的 MWPhotoBrowser 項(xiàng)目地址

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

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

  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,028評論 4 61
  • WebSocket-Swift Starscream的使用 WebSocket 是 HTML5 一種新的協(xié)議。它實(shí)...
    香橙柚子閱讀 24,696評論 8 183
  • 貓小姐和x先生,從來沒有見過面。兩個(gè)人只是在學(xué)校論壇上聊天。卻也有的沒的聊了兩年了。 兩個(gè)人第一次聊天...
    媚狐魅閱讀 239評論 3 1
  • 月兒參加比賽的作品: 眼睛畫在哪里? 眼睛為什么會(huì)是在這里?
    譯丹Sunshine閱讀 319評論 0 0
  • 學(xué)生時(shí)代"八股"居多,不過小弟學(xué)藝不精,肚子里墨水又少,不免提筆犯難。故而往往只得劍走偏鋒,投機(jī)取巧,寫一些"獵奇...
    俊佑的日常閱讀 549評論 5 5

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