Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7066157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:03:02+00:00 2026-05-28T05:03:02+00:00

I am a rookie in iOS programming. In my test app I’d like to

  • 0

I am a rookie in iOS programming. In my test app I’d like to download some xml data from a server and make some annotations from it. It works great, and as a next step I changed it to be asynchronous by dispatching.

Everything works great, but I don’t know how to handle exceptions in this scenario? Where/how to handle if the server is unavailable? Where/how to handle if there is no network connection? Where/how to handle connection time outs?

My test code looks like this:

dispatch_queue_t downloadQueue = dispatch_queue_create("test data fetcher", NULL);
dispatch_async(downloadQueue, ^{
    NSString* fetchedXML = [Fetcher getTestData:@"http://127.0.0.1:11111"];
    dispatch_async(dispatch_get_main_queue(), ^{
        NSArray *annotations = [TestAnnotation getFromXML:fetchedXML];
        self.annotations = annotations;
    });
});
dispatch_release(downloadQueue);

Te most relevant part of Fetcher’s getTestData method

NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
NSURLResponse *response = nil;
NSError *error = nil;

NSData *responseData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];
NSString *responseString = [[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding];

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:03:03+00:00Added an answer on May 28, 2026 at 5:03 am

    You are passing an NSURLResponse and NSError by reference to the sendSynchronous selector of NSURLConnection. When this selector returns, those objects will be populated with the data you are after.

    1) Instead of passing NSURLResponse, pass NSHTTPURLResponse, which is a subclass that will allow you to inspect the HTTP status code (response.statusCode) for non-200 codes.

    2) Check to see if the return value from sendSynchronous is nil and inspect the NSError object for information about the error condition. This is where timeouts and other connectivity issues will appear.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this is a really rookie question but would like some understanding off
I am a Java rookie and need some help with my code. I am
Quick rookie question please. Suppose I have a javsacript object like so: var meh=[[cars,27],
I'm a rookie trying to search a text file for some serial numbers. I'm
So I feel like a serious rookie right now, but I have a problem
Okay this is probably a rookie question, but I have never done GUI programming
I guess it's some basic mistake since I'm still a rookie. package pl.cashflowmanager; //all
I'm a rookie with LINQ to XML and I've got this code that works
I'm a rookie starting to learn Fiddler2 chasing some problems with my ASP.NET webforms
Apologies for the rookie Q - trying to learn Flex/Actionscript and just having some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.