我查詢過這個論壇幾個小時尋找我的問題的想法/答案/解決方案,但每次都空出來。取消iPhone SDK中的SynchronousRequest。 (超時間隔不工作)
我已經使用以下創建的SynchronousRequest:
NSMutableURLRequest *theRequest = [[NSMutableURLRequest alloc] initWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [params length]];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setTimeoutInterval:3.0];
[theRequest setCachePolicy:NSURLRequestReturnCacheDataElseLoad];
[theRequest setHTTPBody: [params dataUsingEncoding:NSUTF8StringEncoding]];
NSData *aData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];
的連接被建立,並且該數據被成功地檢索到ADATA。 但是,當有連接問題,或者服務器不可用時,請求正在嘗試連接75秒這對於超時間隔來說太長時間了, 我已經添加了setTimeoutInterval
參數(3秒)但它不影響連接,
我看到一些人說我應該使用NSTimer和runLoop, 一些答案,但我不清楚這應該如何實現。
請幫助!
用戶在得到超時錯誤消息之前等待75秒!這是可笑的
感謝您的幫助。
謝謝你,我會檢查它,並讓你知道 – 2010-10-05 16:09:23
+1:很好的答案甜蜜的堅果。 – Alan 2011-03-21 21:07:52