Check whether NSURLConnection failed or not
I am using NSURLConnection in order to get some xml files from a web server. When the server is down, I wan开发者_如何学Pythont to inform the user. I cannot find any delegate for checking if the request did succeed or not.
As I understand it - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
is only for receiving errors during the actual download.
Any thoughts?
Thank you
yeah if your server is down then
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[error localizedDescription]
}
method will return the possible reason & u can alert to user :)
didFailWithError will be called if the connection cannot be made as well as if it's interrupted in download.
There's a good class called reachability that you can use to check whether a connection could be made before attempting to establish one (also how it can be made i.e via wifi, 3g etc) - you can find it here
Your NSURLConnection
won't be initialized correctly in this case and you get nil
value returned by the initializer.
Of course you can check device reachibility, but it shouldn't prevent you to check for nil
.
精彩评论