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

  • SEARCH
  • Home
  • 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 7717857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:00:42+00:00 2026-06-01T03:00:42+00:00

I have the following code in my application to load some data from my

  • 0

I have the following code in my application to load some data from my API. It works fine, great in fact in iOS 5 but on iOS 4 I am getting so many responses with status 204.

This only happens on iOS 4, this could have been treated as an API error, but it works great in the browser, on Rested.app, on iOS 5 etc… only iOS 4 fails, it fails in the simulator and on the device (iPhone 4).

I am calling this code each time I load a cell into a table view. I have a core data object with a load state, set to no initially, if it’s not loaded I perform this code, if it’s loaded, I skip this code. In the mean time I display a spinner inside the cell on the table view.

I am sure it’s a problem with multiple requests in GCD on iOS 4.

Can anyone spot anything wrong with my code snippet?

-(void)myFunction{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // query users participations (Network)

        NSError * _urlError = nil;
        NSString * url = [NSString stringWithFormat:@"my api url"];
        NSMutableURLRequest * loginHTTPRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
        [loginHTTPRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"];

        NSLog(@"Description: %@", [loginHTTPRequest description]);

        NSHTTPURLResponse   * _responseHeaders  = nil;
        NSData              * responseData      = [NSURLConnection sendSynchronousRequest:loginHTTPRequest 
                                                                        returningResponse:&_responseHeaders 
                                                                                    error:&_urlError];
        if(_urlError != nil){
            dispatch_async( dispatch_get_main_queue(), ^{
                // alert network connection error
            });
            return;
        }

        NSString *json_string = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

        SBJsonParser *parser = [[SBJsonParser alloc] init];
        NSDictionary * jsonData = [NSDictionary dictionaryWithDictionary:[parser objectWithString:json_string]];
        [json_string release];
        [parser release];

        dispatch_async( dispatch_get_main_queue(), ^{
            // here [_responseHeaders statusCode] keeps returning 204 and there is nothing in responseData

            // do some Core Data stuff
        });

    });
}

UPDATE

Note this code is working fine if called even with a for loop repeatedly, the issue is when I invoke this method from tableView:cellForRowAtIndexPath:

I have Core Data objects with a property “isLoaded” set to NO and changed to YES upon remote load. When my tableview’s datasource loads the cells for each object, the tableView:cellForRowAtIndexPath: method calls this function if the object’s “isLoaded” property is NO.

I suspected the problem may be because there 2 or more simultaneous calls to the API happening when the table is loaded and reloaded. Each successful load from the api invokes reloadData for that tableview.

This lets me have a pre filled tableview with spinners and asynchronously load in my data as I need it on screen which is nice because I can efficiently use NSFetchedResultsController with lazy loading my objects core data.

(I have an endpoint for all my objects returning an array of object id’s – I create Core Data objects with only the ID’s, all rest of data, name, date etc etc… is not loaded until it’s needed).

When I start scrolling around the new cells which are created/reused call this method and they always get a 200 response with the data. it’s only the first loading which causes this “block”.

  • 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-06-01T03:00:43+00:00Added an answer on June 1, 2026 at 3:00 am

    I think I found the problem, I was performing synchronous requests on an asynchronous GCD thread, and for some reason timeouts were occurring, but only on requests in iOS 4, maybe the headers are sent slightly differently from iOS 4 which is causing the API to take longer to respond ? Or maybe multiple (as in simultaneous to the millisecond) requests sent from different threads synchronously on an asynchronous thread were clashing in the system before being sent ?

    Anyhow… this didn’t seem to be the case calling google.com or even my own private server, so it must be something to do with the headers and multiple requests…

    I am using asi http from github and it’s working a lot more efficiently, now I am not using GCD for these requests, just an ASI queue.

    Any final thoughts on iOS 4 synchronous requests performing on an asynchronous GCD thread with possible timeouts not being respected and returning early with a status 204 ?

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

Sidebar

Related Questions

I have used the following code in a number of applications to load .DLL
I have following code in my application: // to set tip - photo in
I have following code in my Application. Comments in my code will specify My
I have following code in my application. [self.navigationController pushViewController:x animated:YES]; It will push a
I have the following code in a strongly-typed View in my application: <td> <label
Work on this small test application to learn threading/locking. I have the following code,
I have the following automation code: lPrintSetup := fWordObject.Application.Dialogs.Item(wdDialogFilePrintSetup); lPrintSetup.Printer := 'MyPrinter'; lPrintSetup.DoNotSetAsSysDefault :=
I have the following sample code in a VB.NET console application. It compiles and
I have a C# application that includes the following code: string file = relativePath.txt;
I am using the following code to get data from the database( from cs

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.