SDWebImage Image received size is NULL - ios

I am trying to show progress view with SDWebImage but when i try below code then it return "0" in "receivedSize"
[cell. ImageHotDish setImageWithURL:[NSURL URLWithString:picName]
placeholderImage:[UIImage imageNamed:nil]
options:0 progress:^(NSUInteger receivedSize, long long expectedSize) {
NSLog(#"Downloaded = %#",receivedSize);
} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
[cell.ImageHotDish setImageWithURL:[NSURL URLWithString:picName]];
}];
I am getting null velue in "receivedSize"
Can any one tell me where i am doing wrong
I have already check this solution but its not showing progress but just an activity indicator. What i am trying to get how much image have been downloaded.
Show activity indicator in SDWebImage

Related

want to know if the image is not available at url using SDWebImage

in my application i am downloading an image from url from webservice using SDWebImage Library. I have nothing problem with this code
[imgQuestionContainer sd_setImageWithURL:[NSURL URLWithString:#"url"] placeholderImage:#"abc.png" options:SDWebImageProgressiveDownload];
with above code i have successfully load the image in imageview...
But my problem is that if i have url for the image but image is not available at that particular path of url. So, how to know that image is not available so i can load next data.
Thanks.
[cell.imageView setImageWithURL:[NSURL URLWithString:#"http://www.domain.com/path/to/image.jpg"]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]
success:^(UIImage *image) {
if(image){
}else{
}
}
failure:^(NSError *error) {
}];
];
This is what exactly i wanted.
[imgQuestionContainer sd_setImageWithURL:[NSURL URLWithString:[[arrOfLoadedPuzzel objectAtIndex:0] objectForKey:#"puzzle_question"]]
placeholderImage:nil
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL)
{
if(error)
{
// image is not available
}
else
{
// image is available
}
}];

SDWebImage animate images

I tried over 100 methods to animate images using SDWebImage but always fail. Do I understand good to using blocks? I am having IBOutlet property image names images1. I made array to store values and animate 3 images.
NSMutableArray *imagegallery = [[NSMutableArray alloc] init];
NSLog(#"IMAGES-%#", imagegallery);
[self.images1 setImageWithURL:[NSURL URLWithString:[self.objc objectForKey:#"Img1"]]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
[imagegallery addObject:image];
NSLog(#"Ima1-------%#", image);
}];
[self.images1 setImageWithURL:[NSURL URLWithString:[self.objc objectForKey:#"Img2"]]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
[imagegallery addObject:image];
}];
[self.images1 setImageWithURL:[NSURL URLWithString:[self.objc objectForKey:#"Img3"]]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
[imagegallery addObject:image];
}];
self.images1.animationImages = imagegallery; //this line gets error
self.images1.animationDuration = 0.5;
[self.view addSubview:self.images1];
[self.images1 startAnimating];
I think when you set self.images1.animationImages = imagegallery because your image couldn't be loaded yet, method setImageWithURL:placeholderImage:completed: is an asynchronous function. you should try another way
like:
Animate images in uiimageview
The problem is that imageGallery contains strings as well as the images you add in the completed block. There's no reason to set imageGallery to be a copy of animatee in the first place since you never use those strings in imageGallery. Just create a new empty mutable array for imageGallery.

SDWebImage causing slow image binding

I am using SDWebImage to cache my images. Overall it looks good but when I use setImageWithUrl method, it take a bit longer to bind the image back to my collection view. Is there a solution to this problem? I tried the following, but looks like it's still having the same problem.
__weak UIImageView *weakImageView = pictureImageView;
[pictureImageView setImageWithURL:[NSURL URLWithString:picture.attachment.url] placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
weakImageView.image = image;
}];

iOS Collection View Scrolling Lags

I am using a UI Collection View to display cells with images and its associated data (like date, name) in a vertical scrolling format. The image data is fetched from the server when the view appears. The fetched data is then converted to UIImage when the cell appears.
The issue is scrolling is laggy. Everytime a new cell is about to appear, the scrolling hangs up a little. Is there a way to solve this problem? I was thinking of starting the conversion of NSData to UIImage in a background thread to prevent lag. Not sure if it is the right way.
As stack says, you should be loading the images asynchronously, and there are wonderful UIImageView categories that make this really easy to do, namely the category in SDWebImage or in AFNetworking. These UIImageView categories not only load images asynchronously, but also do caching, cancel network operations if necessary, etc. It takes a lot of code if you do this properly yourself (capturing all of those features I just enumerated), but it's really easy if you use one of these categories.
For example, if using SDWebImage, you can:
#import "UIImageView+WebCache.h"
and then:
[cell.imageView setImageWithURL:url placeholderImage:[UIImage imageNamed:#"placeholder.png"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
if (error)
NSLog(#"%s: setImageWithURL error: %#", __FUNCTION__, error);
}];
Or, if using AFNetworking:
#import "UIImageView+AFNetworking.h"
and
[cell.imageView setImageWithURL:url placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
or
[cell.imageView setImageWithURLRequest:[NSURLRequest requestWithURL:url] placeholderImage:[UIImage imageNamed:#"placeholder.png"] success:nil failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
NSLog(#"%s: setImageWithURLRequest error: %#", __FUNCTION__, error);
}];

SDwebimage is not responding second time

I am facing the issue ,below is the code. It shows error for the very first time and then no completion block is calling .
[self.comicsImage setImageWithURL:[NSURL URLWithString:self.imageUrl]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)
Please help. If the image is not on the server it shows error first time then it does nothing on again requesting the same URL.Thanks in advance.
Because it caches the retured image for the requested url, 2nd time it returns what is in the cache for the given url.
Try this code, it should work for you
[self.comicsImage setImageWithURL:[NSURL URLWithString:self.imageUrl]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType){
if (cacheType == SDImageCacheTypeNone)
{
//your code here
}
}];

Resources