Graphics Programs Reference
In-Depth Information
NSLog(@"xmlCheck = %@", xmlCheck);
}
There is a possibility that a connection will fail. If an instance of NSURLConnection
cannot make a connection to a web service, it sends its delegate the message connec-
tion:didFailWithError: . Note that this message gets sent for a connection fail-
ure, like having no Internet connectivity or if the server doesn't exist. For other types of
errors, such as data sent to a web service in the wrong format, the error information is re-
turned in connection:didReceiveData: .
In ListViewController.m , implement connection:didFailWithError: to
inform your application of a connection failure.
- (void)connection:(NSURLConnection *)conn
didFailWithError:(NSError *)error
{
// Release the connection object, we're done with it
connection = nil;
// Release the xmlData object, we're done with it
xmlData = nil;
// Grab the description of the error object passed to us
NSString *errorString = [NSString stringWithFormat:@"Fetch failed: %@",
[error localizedDescription]];
// Create and show an alert view with this error displayed
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Error"
message:errorString
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[av show];
}
Try building and running your application. You should see the XML results in the console
shortly after you launch the application. If you put your device in Airplane Mode (or if it
is not connected to a network), you should see a friendly error message when you try to
fetch again. (For now, you will have to restart the application from Xcode in order to
refetch the data after you've received the error.)
The XML that comes back from the server looks something like this:
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>forums.bignerdranch.com</title>
<description>Topics written by Big Nerd Ranch</description>
...
<item>
Search WWH ::




Custom Search