1. Identify third-party libraries

First, go directly to the SDWebImage warehouse, which directly has the WebP warehouse address

That isSDWebImageWebPCoderDirectly,pod 'SDWebImageWebPCoder'Will do. If SDWebImage is not in the project, yespod 'SDWebImage')

Be careful here!! ispod 'SDWebImageWebPCoder'

I’m searching for SDWebImage to load WebP, and the high weight answer ispod 'SDWebImage/WebP', but I cannot search this repository in SDWebImage Repositories, that is to say, there is no repository. The result is shown in the figure below.

Guess before the old warehouse is this name, those articles have not been updated, but the weight is high, inevitably mistake a person’s children.

2. Import SDWebImageWebPCoder

There is a high probability that pod install will receive an error because libwebp is not connected.

1. Enter Pod repo on the terminal to check cocoapods’ PATH on the machine

2. Copy the path of the trunk. Command + shift + G enter the address of the previous step and click on Specs–>1–>9–>2–>libwebp. (Note that your path may be the path of Cocoapods.)
3, select the error version to open, change the source git address toGithub.com/webmproject…

4,pod install[root@source-git] [root@source-git] [root@source-git]

3. Use SDWebImageWebPCoder

SDImageWebPCoder *webPCoder = [SDImageWebPCoder sharedCoder];
[[SDImageCodersManager sharedManager] addCoder:webPCoder];

NSData *webpData;
UIImage *wimage = [[SDImageWebPCoder sharedCoder] decodedImageWithData:webpData options:nil];      
Copy the code
NSData *webpData;
[UIImage sd_imageWithWebPData:webpData];
Copy the code
After testing the above two writing methods can successfully load webP images