SDWebImage本身就支持webp,但是webp在TC有個蛋疼的問題就是VPN,工程中經常執行pod update 耗時耗力,然後我就直接扔在本地了。
方法
- 在終端直接配置翻牆直接執行pod update,然後直接拷貝到本地目錄直接引入
純手工操作
由於我的vpn出問題了麼有執行pod update 成功,https://chromium.googlesource.com/webm/libwebp 執行到這兒一直超時。我直接去https://chromium.googlesource.com/webm/libwebp 地址直接下載工程。
工程中有一個iosbuild.sh腳本,然後直接執行。但是發現執行完的framewrok中並沒有 這幾個爲紅色的文件並沒有,但SDWebImage中
/*
* This file is part of the SDWebImage package.
* (c) Olivier Poitrey <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
#ifdef SD_WEBP
#import "UIImage+WebP.h"
#import "webp/decode.h"
#import "webp/mux_types.h"
#import "webp/demux.h"
#import "NSImage+WebCache.h"
#import "objc/runtime.h"
// Callback for CGDataProviderRelease
static void FreeImageData(void *info, const void *data, size_t size) {
free((void *)data);
}
顯而易見,報錯了,引入的文件沒有,但是看一下工程結構。
工程中都有該文件,顯然在執行iosbuild.sh沒有打包進去,那我們做的就非常簡單了。
- 最後一步修改 iosbuild.sh腳本,125行加入別的幾個類文件,執行./iosbuild.sh 生成的framework就可以用了。
cp -a ${SRCDIR}/src/webp/{config,demux,format_constants,mux_types,mux,decode,encode,types}.h ${TARGETDIR}/Headers/
${LIPO} -create ${LIBLIST} -output ${TARGETDIR}/WebP
還有一種方法:
YYImage(本身也支持webp,直接使用也沒有問題,由於我們之前使用的sd,就沒有換了)也支持了https://github.com/ibireme/YYWebImage 直接copy YYWebImage/Vendor/WebP.framework 使用也沒有問題。