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 8532277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:40:46+00:00 2026-06-11T09:40:46+00:00

I have some code that makes a http call to a json based webservice.

  • 0

I have some code that makes a http call to a json based webservice. That’s working fine but I tried to move the code to it’s own class and I have a slight hang up. When I call the method, the main thread just continues to the next command without wait for a response from my method.

Here’s some code from the main part of the program

[newcall run];
    NSLog(@"%@",[newcall status]);
    NSArray *resultarray= [newcall returndata];
    for (NSString *element in resultarray) {
        NSLog(@"%@",element);
}

My Header

#import "AFHTTPClient.h"

@interface jsoncall : AFHTTPClient
{
    NSString* Date;
    NSString* apps;
    NSString* data1;
    NSURL* url;
    NSString* Path;
    NSArray* returndata;
    NSString* status;
}

-(void) setApp: (NSString *)input;

-(void) setData: (NSString *)input;

-(void) setURL: (NSString *)input;

-(void) setPath: (NSString *)input;

-(int) run;

-(NSArray *) returndata;
-(NSString *) status;

@end

My run method

-(int) run
{
    __block int success;
    NSDictionary* jsonDictionary=[NSDictionary dictionaryWithObject: data1 forKey:@"data"];
    NSString* jsonString = [jsonDictionary JSONRepresentation];
    AFHTTPClient *httpClient=[[AFHTTPClient alloc] initWithBaseURL:url];
    NSDictionary *params =[NSDictionary dictionaryWithObjectsAndKeys:
                           apps,@"app",
                           jsonString,@"smpdata",nil];
    NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:Path parameters:params];

    AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
                    success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
                        NSArray *dataarray=[JSON valueForKey:@"Data"];
                        status= [NSString stringWithFormat:@"%@",[JSON valueForKeyPath:@"Status"]];
                        NSLog(@"%@",status);
                        returndata= dataarray;
                        success=1;
                        NSLog(@"Success: Made it here");
                    }
                    failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error,id JSON)
                    {
                        success=0;
                        NSLog(@"Error: Made it here");
                    }
    ];

    [operation start];
    [operation waitUntilFinished];
    return success;
}
  • 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-11T09:40:47+00:00Added an answer on June 11, 2026 at 9:40 am

    The method I used was Asychronous and as such I would have to have chained the next set of processing by calling it from the completion block. When the final app is done, we may do that but there’s also this solution.

    Waiting for completion block to complete in an AFNetworking request

    By switching AFJSONRequestOperation to NSURLConnection, I am able to use Sychronous Mode which means the request has to complete before the thread moves on.

    NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:Path parameters:params];
    
    NSURLResponse *response = nil;
    NSError *error = nil;
    
    NSData *data=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    
    if (error) {
        NSLog(@"Error: %@",error);
    }
    else {
        id JSON = AFJSONDecode(data, &error);
        NSArray *dataarray=[JSON valueForKey:@"Data"];
        status= [NSString stringWithFormat:@"%@",[JSON valueForKeyPath:@"Status"]];
        NSLog(@"%@",status);
        returndata= dataarray;
    
    }
    

    For our needs Synchronous mode should work fine for now.

    However

    You should not run a Synchronous web call on an UI thread because it will block and make your UI unresponsive. That means you need to put your call to this class in it’s own thread with any other code that relies on it. I believe you want to check out use of NSOperation but I’m a Objective-c noob so I won’t be adding an example here.

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

Sidebar

Related Questions

I have some PHP code that was at one point WORKING FINE. It makes
I have some code that makes heavy use of a thread pool, which I
I have recently made changes in some code that makes a char name field
I have inherited some code that will eventually be part of an API call.
I have some PHP code that is designed to make a spreadsheet with formulas
we have some C++ code that we need to create a make file in.
I have some transliteration tables in code that are formated to make it easier
Welcome, I notice that Youtube make some changes into their website code. Anyone have
I have some code that will change the background color of a specific label
I have some code that is supposed to return an NSString. Instead it is

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.