Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-15-2010, 11:43 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 9
roko is on a distinguished road
Default NSXMLParser: handling connection errors

Hi, i need help. I have some method where xml file is being loaded from url.

Code:
- (id) loadXMLByURL:(NSString *)urlString{
	
	NSURL *url = [NSURL URLWithString:urlString];
	
	//NSXMLParser *parser
	parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
	
	parser.delegate = self;

	[parser parse];

	return self;
	
}
It works fine. But i want to have ability to handle connection errors(for example if connection is torn or there is not needed file).
How can i do it? Any examples of code, thoughts and references would be appreciated.

Michael
roko is offline   Reply With Quote
Old 09-15-2010, 03:45 PM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

look at NSXMLParser delegate

You can implement this delegate method
Code:
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)
smithdale87 is offline   Reply With Quote
Old 09-15-2010, 07:14 PM   #3 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 9
roko is on a distinguished road
Default

Quote:
Originally Posted by smithdale87 View Post
look at NSXMLParser delegate

You can implement this delegate method
Code:
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)
smithdale87, thanks a lot for your help. It works fine.

my code is that:
Code:
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError {

	NSString * errorString = [NSString stringWithFormat:@"Unable to download data (Error code %i )",[parseError code]];

	UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Error loading content" message:errorString 
														 delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

	[errorAlert show];
}
Let me know if you have noticed some bugs or shortcoming. Thanks.
roko is offline   Reply With Quote
Reply

Bookmarks

Tags
connection, error, handling, network, nsxmlparser

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 326
19 members and 307 guests
2ndSegment, bignoggins, cayladv57, cgokey, dermotos, djohnson, Domele, guusleijsten, Hamad, heshiming, linkmx, markuschow, Objective Zero, pungs, Rudy, Sloshmonster, teebee74, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:53 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0