I'm using SDWebImage to load images in my iOS app and I now want to use the webp format.
Here's my first try :
NSURL *url = [NSURL URLWithString:@"http://www.gstatic.com/webp/gallery/2.webp"];
[self.imageView setImageWithURL:url
placeholderImage:nil
options:SDWebImageProgressiveDownload
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
if (error) {
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[av show];
}
}];
It would work perfectly if the image was a jpeg (I tried) but with a webp it doesn't. The first time I call this code the error is :
Downloaded image has 0 pixels
Then the error turns to :
The operation couldn't be completed. (NSURLErrorDomain error -1100.)
What's wrong?
Actually the code above should work but the webp support is disabled by default in the library.
Adding SD_WEBP=1
in the preprocessor macros of the sdwebimage target (in build settings) will enable webp support
Add
pod 'SDWebImage/WebP'
into your podfile and then hit pod install. Cocoapods is gonna take care of the preprocessor flag as well.
From SDWebImage github page
There are 3 subspecs available now: Core, MapKit and WebP (this means you can install only some of the SDWebImage modules. By default, you get just Core, so if you need WebP, you need to specify it).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With