我在我的iPhone應用程序中有用戶身份驗證。用戶登錄以應用程序將用戶名/密碼發送到Web服務進行用戶檢查的方式工作。我現在的問題是我不知道如何設置「超時」(30秒)並停止從Web服務請求數據?如何取消網絡服務呼叫 - IOS
NSString *soapMsg =
[NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>...", username, password
];
NSURL *url = [NSURL URLWithString: @"http://...Service.asmx"];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMsg length]];
[req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req addValue:@"http://.../LoginUser" forHTTPHeaderField:@"SOAPAction"];
[req addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
if (conn)
{
webData = [[NSMutableData data] retain];
}
我添加 '[REQ setTimeoutInterval:30];'。現在如果請求超時,這個處理程序在哪裏?它是' - (void)連接:(NSURLConnection *)連接didFailWithError:(NSError *)錯誤'? – 1110