我想验证天气连接是否成功,但一直得到不稳定的结果。当我尝试使用伪造的URL与做一个同步请求:NSURLConnection验证
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if (responseData)
{
did_send = TRUE;
}
else
{
did_send = FALSE;
}
它挂了一段时间的最终返回:
did_send = FALSE;
但如果我这样做使用伪造的URL与异步请求:
NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:request delegate:self ];
if (conn)
{
did_send = TRUE;
}
else
{
did_send = FALSE;
}
我得到:
did_send = TRUE;
每次。我需要使异步请求正常工作,因为我可以设置超时而不必挂起60秒,而请求超时且超时时间与异步请求不可更改。有任何想法吗?
它不是一个真正的答案,但对于异步请求,我发现使用ASIHTTPRequest比Apple apis本身更容易/易于理解。 – 2010-08-16 18:49:51