Iphone iOS为SDWebImage中的url请求设置超时
我正在使用SDWebImage库在iOS应用程序中缓存图像。现在,当从服务器加载映像时,我在imageview上显示一个活动指示器。我正在使用以下代码Iphone iOS为SDWebImage中的url请求设置超时,iphone,ios,sdwebimage,Iphone,Ios,Sdwebimage,我正在使用SDWebImage库在iOS应用程序中缓存图像。现在,当从服务器加载映像时,我在imageview上显示一个活动指示器。我正在使用以下代码 __block UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; activityIndicator.ce
__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];
}];
它一般工作正常。但是对于一些ImageURL,它没有加载图像,因此它永远不会到达完成块&活动指示器旋转无限。
那么,有没有办法设置一个超时,这样在一段时间后,它会给我一个错误或类似的东西,这样我就可以停止活动指示器
有点银色。请提供帮助。您应该检查URL是否有效,因为当您将
nil
传递给setImageWithURL
时,不会调用完成块
NSURL* url = [NSURL URLWithString:[self.service valueForKey:@"image"]];
if (url)
[self.serviceImageView setImageWithURL:url placeholderImage:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
[activityIndicator removeFromSuperview];
}];
I
url还可以,但没有返回任何图像,我只是第一次看到它工作正常。在此之后,SDWebImage将url列入黑名单,因此它没有调用完成块。我必须使用选项SDWebImageRetryFailed