NSURLConnection didFailWithError not called?

2020-04-16 03:43发布

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?

1条回答
Evening l夕情丶
2楼-- · 2020-04-16 04:03

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).

查看更多
登录 后发表回答