Cable W
Cable W

Reputation: 673

sendAsynchronousRequest got Timeout Error on iPhone

My App allows user to take photo and upload it to a PHP server. I use sendAsynchronousRequest calls to send data (form with photo files) to the server. All those calls are working just fine on my iPad 2 when debugging. But when I debugged it on iPhone 4S, some of them get errors with error code, -1001, which represents Timeout error. I tried for thousand times in the past two days to find its root cause, but I still can't find one.

Has anybody encounters similar situation? or knows why?

The only clue I got is that if there are more than one file in the request data (original photo file and resized thumb file), it will receive time out error. Is it about request (photo file) size? or file number?

Upvotes: 0

Views: 1100

Answers (2)

Guru
Guru

Reputation: 5373

I handled the ASIHTTP request failed using this simple method.

- (void)requestFailed:(ASIHTTPRequest *)request {

    NSError *error = [request error];

    if([error code] == ASIRequestTimedOutErrorType ) {

        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error"
                                                       message:@"Connection Timed out" 
                                                      delegate:self 
                                             cancelButtonTitle:@"Ok"
                                             otherButtonTitles:nil];
        [alert show];
        return;
    } else if ( [error code] == ASIConnectionFailureErrorType) {

        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" 
                                                       message:@"Connection Failiure"
                                                      delegate:self
                                             cancelButtonTitle:@"Ok" 
                                             otherButtonTitles:nil];
        [alert show];
        return;

    }
}

You can also set your connection time out in your request like

[request_ setTimeOutSeconds:50.0];

This will wait for 50 seconds and show connection timed out error.

Upvotes: 1

Cable W
Cable W

Reputation: 673

I solved the problem. It caused by upload big size file. The original photo token by iPhone 4s is about 5M big. If the network is not fast enough, the connection will be time out.

Upvotes: 0

Related Questions