2011-07-22 2 views
0

私の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]; 
    }  

答えて

4
[req setTimeoutInterval:urInterval]; 
+0

setTimeoutInterval: 

Sets the receiver’s timeout interval, in seconds.

- (void)setTimeoutInterval:(NSTimeInterval)timeoutInterval

Parameters

timeoutInterval

The timeout interval, in seconds. If during a connection attempt 

the request remains idle for longer than the timeout interval, the request is considered to have timed out. The default timeout interval is 60 seconds.

I 'は[REQのsetTimeoutInterval:30];' 追加。そして今、リクエストがタイムアウトした場合、これのハンドラはどこですか?それは ' - (void)connection:(NSURLConnection *)connection didFailWithError :(NSError *)error'ですか? – 1110

0

あなたはたぶんASIHTTPはあなたを助けるかもしれないNSURLConnection

/*! 
    @method cancel 
    @abstract Cancels an asynchronous load of a URL. 
    @discussion Once this method is called, the asynchronous load is 
    stopped, and the NSURLConnectionDelegate associated with the 
    receiver will no longer receive any asynchronous callbacks for 
    this NSURLConnection. 
*/ 
- (void)cancel; 
0

の解除方法を使用することができますか?

また、あなたが正しく理解していれば、大部分はsimilar issueがstackoverflowにあります。

関連する問題