2011-01-10 6 views
0

私は現在、RSSフィードをhttp://www.learnerstogether.net/から利用するアプリケーションを行っています。しかし、私はエラーがウェブサイトからXMLデータをダウンロードすることができない取得しています。誰かが間違っていることを教えてもらえるか?RSSリーダーエラー

@implementation Parser 
@synthesize items, responseData; 
@synthesize currentTitle; 
@synthesize currentDate; 
@synthesize currentSummary; 
@synthesize currentLink; 
@synthesize currentPodcastLink; 

- (void)parseRssFeed:(NSString *)url withDelegate:(id)aDelegate { 
    [self setDelegate:aDelegate]; 

    responseData = [[NSMutableData data] retain]; 
    NSURL *baseURL = [[NSURL URLWithString:url] retain]; 


    NSURLRequest *request = [NSURLRequest requestWithURL:baseURL]; 

    [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease]; 
} 

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{ 
    [responseData setLength:0]; 
} 

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{ 
    [responseData appendData:data]; 
} 

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 
{ 
    NSString * errorString = [NSString stringWithFormat:@"Unable to download xml data (Error code %i)", [error code]]; 

    UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Error loading content" message:errorString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    [errorAlert show]; 
} 

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
    self.items = [[NSMutableArray alloc] init]; 

    NSXMLParser *rssParser = [[NSXMLParser alloc] initWithData:responseData]; 

    [rssParser setDelegate:self]; 

    [rssParser parse]; 
} 

#pragma mark rssParser methods 

- (void)parserDidStartDocument:(NSXMLParser *)parser { 
} 

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ 
    currentElement = [elementName copy]; 

    if ([elementName isEqualToString:@"item"]) { 
     item = [[NSMutableDictionary alloc] init]; 
     self.currentTitle = [[NSMutableString alloc] init]; 
     self.currentDate = [[NSMutableString alloc] init]; 
     self.currentSummary = [[NSMutableString alloc] init]; 
     self.currentLink = [[NSMutableString alloc] init]; 
     self.currentPodcastLink = [[NSMutableString alloc] init]; 
    } 

    // podcast url is an attribute of the element enclosure 
    if ([currentElement isEqualToString:@"enclosure"]) { 
     [currentPodcastLink appendString:[attributeDict objectForKey:@"url"]]; 
    } 
} 

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{ 

    if ([elementName isEqualToString:@"item"]) { 
     [item setObject:self.currentTitle forKey:@"title"]; 
     [item setObject:self.currentLink forKey:@"link"]; 
     [item setObject:self.currentSummary forKey:@"summary"]; 
     [item setObject:self.currentPodcastLink forKey:@"podcastLink"]; 

     // Parse date here 
     NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; 

     [dateFormatter setDateFormat:@"E, d LLL yyyy HH:mm:ss Z"]; // Thu, 18 Jun 2010 04:48:09 -0700 
     NSDate *date = [dateFormatter dateFromString:self.currentDate]; 

     [item setObject:date forKey:@"date"]; 

     [items addObject:[item copy]]; 
    } 
} 

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{ 
    if ([currentElement isEqualToString:@"title"]) { 
     [self.currentTitle appendString:string]; 
    } else if ([currentElement isEqualToString:@"link"]) { 
     [self.currentLink appendString:string]; 
    } else if ([currentElement isEqualToString:@"description"]) { 
     [self.currentSummary appendString:string]; 
    } else if ([currentElement isEqualToString:@"pubDate"]) { 
     [self.currentDate appendString:string]; 
     NSCharacterSet* charsToTrim = [NSCharacterSet characterSetWithCharactersInString:@" \n"]; 
     [self.currentDate setString: [self.currentDate stringByTrimmingCharactersInSet: charsToTrim]]; 
    } 
} 

- (void)parserDidEndDocument:(NSXMLParser *)parser { 
    if ([_delegate respondsToSelector:@selector(receivedItems:)]) 
     [_delegate receivedItems:items]; 
    else 
    { 
     [NSException raise:NSInternalInconsistencyException 
        format:@"Delegate doesn't respond to receivedItems:"]; 
    } 
} 

#pragma mark Delegate methods 

- (id)delegate { 
    return _delegate; 
} 

- (void)setDelegate:(id)new_delegate { 
    _delegate = new_delegate; 
} 

- (void)dealloc { 
    [items release]; 
    [responseData release]; 
    [super dealloc]; 
} 
@end 
+0

あなたの質問は恐ろしいです.GDBコンソールのBack Traceコマンドを使用して正確にクラッシュする箇所を編集してください。 – Tirth

+0

iPhoneでRSSを解析する場合は、[FeedParser](https://github.com/kballard/feedparser)をご覧ください。 –

答えて

0

あなたのエラーは、このRSS解析の側面とはまったく関係ありません。さらに、あなたは完全なエラーに貼り付けていません。あなたの実装では、エラーオブジェクト自体を-connection:didFailWithError:に記録する必要があります。それは何がうまくいかなかったのか人間が判読できる説明を与えるはずです。