I'm using SDWebImage library for caching image in my iOS app. Now when loading image from server I'm showing an activity indicator on the imageview. I'm using the following code
__block UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.center = self.serviceImageView.center;
activityIndicator.hidesWhenStopped = YES;
[activityIndicator startAnimating];
[self.serviceImageView addSubview:activityIndicator];
[self.serviceImageView setImageWithURL:[NSURL URLWithString:[self.service valueForKey:@"image"]] placeholderImage:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
[activityIndicator removeFromSuperview];
}];
It works fine generally. But for some imageurls it didn't load the image and so it never comes to completed block & the activity indicator is spinning infinite. So is there any way to set a timeout so that after a certain amount of time it gives me an error or something like that so I can stop the activity indicator.
It's bit argent. Please help.