From my experience working with web services and also AFHTTPRequest, the request timed out is mostly server/network related. If you are confirmed that the server does not have any problem, I think the best you can do is giving the request to a timeoutInterval (eg: 15 seconds). Next, if you still receive the request timed out error, you can make a try the same operation for N times.
For example, you can do something like:-
Calling the function with 3 retries:
[ServerRequest yourMethodName:yourLoginDict with:3];
The Function:-
+(void)yourMethodName:(NSDictionary *) loginParams with:(NSUInteger)ntimes {
if (ntimes <= 0) {
NSLog(@"Request failed after trying for N times");
}
else{
NSDictionary * postDictionary = loginParams;
NSError * error = nil;
NSData * jsonData = [NSJSONSerialization dataWithJSONObject:postDictionary options:NSJSONWritingPrettyPrinted error:&error];
NSString * urlString = [NSString stringWithFormat:@"%@",@"YOUR URL"];
//Give the Request 15 seconds to load
NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:15.0];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody:jsonData];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:urlRequest];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Successful request");
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Request Failed at %d: %@",ntimes,error);
//If the request failed, call again with ntimes-1
[self yourMethodName:loginParams with:ntimes-1];
}
];
[operation start];
}
}
I hope this helps.