NSURLConnection didFailWithError没有调用? [英] NSURLConnection didFailWithError not called?
本文介绍了NSURLConnection didFailWithError没有调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:@http://www.google.com /images/someImageIknowDoesntExist.jpg]
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:10.0];
urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
不触发didFailWithError。如何获得通知,我尝试连接的URL没有图像?
解决方案
响应中的状态代码当您获得连接时,将为404:didReceieveResponse:
方法。错误方法仅在获取URL时出现实际错误(如网络故障或主机不存在等))才被调用。
Why, when an image does not exist at a specified URL, does didFailWithError not get called? For example:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com/images/someImageIknowDoesntExist.jpg"]
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:10.0];
urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
Does not trigger didFailWithError. How can I get notified that there is no image at the url I try to connect to?
解决方案
The status code in the response will be 404 when you get the connection:didReceieveResponse:
method. The error method only gets called if there was an actually error fetching the URL (like the network went down, or the host doesn't exist, etc).
这篇关于NSURLConnection didFailWithError没有调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文