ASIHTTPRequest Request Timeout

I have been working on this problem for a long time, and I am not sure how to continue to solve it.

I have a simple ASIHTTPRequest. The code is below.

The application always works when I launch it. I have a table view that I can extract to update, which triggers ASIHTTPRequest, and I can update as many times as I like with the problem. I can send the application to the background and return it, and everything works fine. But if I leave the application for several hours and return, sometimes I will start to receive an error when requesting. As soon as this happens, the error will be repeated every time I try to update, and I can never connect again without closing the application and restarting it.

I don't believe the problem is with my url because it can get stuck on one device while it works fine on another device. I could never get a time error on a simulator.

I can imagine why one day I can get a timeout error, but I can’t understand why, once it starts, the error never stops. I really don't know where to look for an attempt to fix this, or how I can debug it.

Perhaps it would be important to note that I am currently using TestFlightLive, GoogleAnalytics, and Urban Airship in my application. Perhaps one of these libraries is causing a problem with my network behavior?

Here is the code:

- (void)getData { NSURL *url = [NSURL URLWithString:@"http://www.mysite.com/appname/latestData.py?callback=?"]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request setDelegate:self]; [request setTimeOutSeconds:20.0]; [request startAsynchronous]; } - (void)requestFinished:(ASIHTTPRequest *)request { NSData *responseData = [request responseData]; DLog(@"requestFinished entered"); NSString *dataString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; // Update the data model if (dataString != nil) { SBJsonParser *jsonParser = [[SBJsonParser alloc] init]; NSDictionary *dataDictionary = [jsonParser objectWithString:dataString error:NULL]; [self updateDataModel:dataDictionary]; } [self refreshIsFinished]; } - (void)requestFailed:(ASIHTTPRequest *)request { NSError *error = [request error]; // inform the user ELog(@"Connection failed! Error - %@ %@", [error localizedDescription], [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]); UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:NSLocalizedString(@"CONNECTION_FAILED_MESSAGE",nil) delegate:nil cancelButtonTitle:NSLocalizedString(@"CLOSE",nil) otherButtonTitles:nil]; [alertView show]; [self updateUI]; [self refreshIsFinished]; } 
+4
source share

Source: https://habr.com/ru/post/944009/


All Articles