1

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.

Wain
  • 118,658
  • 15
  • 128
  • 151
josh
  • 1,681
  • 4
  • 28
  • 61
  • Be aware that [ASIHTTPRequest](http://allseeing-i.com/ASIHTTPRequest/) is no longer supported nor recommended for new work. – zaph Oct 13 '14 at 06:45
  • @Zaph Thanks, are you talking about for iOS 7 or 8? – josh Oct 13 '14 at 08:40
  • This support iOS 3.0 and above. – josh Oct 13 '14 at 08:41
  • This thread{http://stackoverflow.com/questions/18595809/asihttprequest-and-afnetworking-in-2013-what-to-choose} shows that this can be use in iOS 6 and iOS 7 but not confirm for iOS8. – josh Oct 13 '14 at 08:44

1 Answers1

1

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

Sport
  • 8,570
  • 6
  • 46
  • 65
  • Thanks, so should I use same Async or Sync with same lines what you suggest? – josh Oct 13 '14 at 06:02
  • [request startSynchronous]; – Sport Oct 13 '14 at 06:14
  • Ok I tried but same result and sorry for not mentioning that this all happening on cellular connection, I know this may has nothing to do with cellular but its only happening on cellular. – josh Oct 13 '14 at 06:18