"Forced" to use sendSynchronousRequest (POST) for our application. Checking if "response" is nil (below) will catch a few of the connection errors that may occur, but I'd like to invoke a timer as well to cancel the request after about 20 s. Not sure on how to do that and how to "wait" for time out. Any suggestions? Thanks in advance.
data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if(response开发者_StackOverflow社区 == nil) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Connection error"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert show];
[alert resignFirstResponder];
[alert release];
} ...
try this:
request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0];
精彩评论