开发者

NSURLConnection didFailWithError not called?

开发者 https://www.devze.com 2023-01-20 21:36 出处:网络
Why, when an image does not exist at a specified URL, does didFailWithError not get calle开发者_如何学Pythond?For example:

Why, when an image does not exist at a specified URL, does didFailWithError not get calle开发者_如何学Pythond? 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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号