Getting response on Asynchronous and time out on synchronous call in ASIFormDataRequest iOS dev

226 views Asked by At

I am calling an API in ASIFormDataRequest with synchronous method and its returning me time out error on each time, logged this error `Error Domain=ASIHTTPRequestErrorDomain Code=2 "The request timed out" time out seconds set to 10s, some time it shows me this error before 10s. But most strange is that when I changed to Asnychronous it start working fine. I know that Synchronous block every thing until it gets response and Asynchronous don't block but what are other ways to make different both of them and why this happen in my case. Here below is my code of what I am doing. Kindly suggest me or guide me why this is happen. Looking for response thanks in advance.

  NSString *finalStrUrl = [NSString stringWithFormat:@"SomeAPI"];
    ASIFormDataRequest *formRequest = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:finalStrUrl]];
    [formRequest setTimeOutSeconds:10];
    [formRequest setRequestMethod:@"GET"];
    [formRequest setAllowCompressedResponse:NO];
    [formRequest setDefaultResponseEncoding:NSUTF8StringEncoding];

if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0

    [formRequest setShouldContinueWhenAppEntersBackground:YES];

endif

    [formRequest setDelegate:self];
    [formRequest startAsynchronous];

Note: This all happening in cellular Connection.

1

There are 1 answers

3
Sport On

try to use the following code to change the timeout interval. This code will set the timeout to 05 seconds:

[request setTimeOutSeconds:05]


[request setNumberOfTimesToRetryOnTimeout:2];

get the more info on this page http://allseeing-i.com/ASIHTTPRequest/How-to-use