ASIHTTPRequest request times out

2020-03-24 06:40发布

I have been working on this issue for a long time, and I am unsure how to proceed trying to solve it.

I have a simple ASIHTTPRequest. The code is posted below.

The app always works when I first run it. I have a table view which I can pull to refresh, which initiates the ASIHTTPRequest, and I can refresh as many times as I like with out problem. I can send the app to the background and bring it back and everything works fine. But if I leave the app for a number of hours and come back, sometimes I will start getting a request timed out error. Once this occurs, the error will repeat every time I try to refresh and I am never able to connect again without actually shutting down the app and restarting it.

I do not believe the problem is with my url, because it can be stuck on one device while fine on another device. I have never been able to get the time out error on the simulator.

I can imagine why I might get the time out error once, but I can't understand why once it starts, the error never stops. I really have no idea where to look to try to fix this, or how I could go about debugging it.

It might be relevant to note that I am currently using TestFlightLive, GoogleAnalytics and Urban Airship in my app. Perhaps one of these libraries is causing a problem with my networking behaviour?

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];
}

0条回答
登录 后发表回答