2011-07-18 11 views
0

RSSフィードからデータを取得するためにNSURLConnectionを使用しています。デフォルトのタイムアウト値を30秒に設定しました。低Wi-Fi接続の状況では、 30秒後に正常に接続が解除されたことを確認します。コールバックが来ると接続が解除されていることを確認します。要求が送信されてから合計30秒後に別のコールバックが取得されます。どこにも追跡されません。NSURLConnectionの問題didFailWithError:接続タイムアウト時にコールバックが複数回送信される

また、私はリクエストを送信するときにこれが最初に表示されます。リクエストを送信する次回は、コールバックが1回だけ表示されます。 同じ問題を抱えている別のスレッドがありますが、誰かが私を助けてくれるのであれば、私は本当に感謝しています。ここで

は私の接続の作成、デリゲート、FailwithErrorとコールバック関数がコールバック関数でアラート表示が通常の30秒タイムアウトと私はすることができません、60秒後に1後twice.Onceと呼ばれている

//MainClass.m 
- (void)LoadRSSFeed { 
if (Stories == nil) { 
    [activityIndicator startAnimating]; 
    rssParser = [[Parser alloc] init]; 
    [rssParser parseRssFeed:@"http://twitter.com/statuses/user_timeline/56202272.rss" withDelegate:self]; 
} else { 
    [newsTable reloadData]; 
} 

} 

//Parser Class where connection is called 
- (void)parseRssFeed:(NSString *)url withDelegate:(id)aDelegate { 
[self setDelegate:aDelegate]; 
ERROR = FALSE; 
responseData = [[NSMutableData data] retain]; 
NSURL *baseURL = [[NSURL URLWithString:url] retain]; 

NSLog(@"Creating Connection"); 
NSURLRequest *request = [NSURLRequest requestWithURL:baseURL  cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0]; 
conn = [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease]; 
} 

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 
{ 
NSLog(@"Error"); 
ERROR = TRUE; 
if (_delegate) 
{ 
    [_delegate receivedItems:nil]; 
} 
else 
{ 

} 
} 

//Delegate Callback Function in MainClass.m 
- (void)receivedItems:(NSArray *)theItems { 

[rssParser setDelegate:nil];//setting delegates to nil 
[rssParser release]; 
rssParser = nil; 

Stories = theItems; 
if([activityIndicator isAnimating]){ 
    if(Stories!=nil) 
    { 
     if([Stories count]) 
     {    
      [newsTable reloadData]; 
     } 
    }else{ 
     NSLog(@"Showing Alert"); 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Time Out" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil, nil]; 
     [alert show]; 
     [alert release]; 
    } 
} 
[activityIndicator stopAnimating]; 
} 

です私がBreakpointsまたはNSlogsをAlertビューの前に追加しても、呼び出されたりキャプチャされたりしません。

ここのヘルプは本当に感謝しています。

Azeem

+0

1つのリクエストのみを送信していることは間違いありませんか? –

答えて

0

–[NSURLConnectionDelegate connection:didFailWithError:]状態は以下のドキュメント:

Once the delegate receives this message, it will receive no further messages for connection .

アラートビューをごParserのデリゲートの実装に示されているので、あなたのParserオブジェクト以外の場所からreceivedItems:を呼び出す可能性があります。実際、ブレークポイントとログステートメントは無視されるので、Parserデリゲートコールバックではなく、タイムアウトアラート(タイマーなど)を示す他のコードを持つことさえできます。

関連する問題