Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone RSS阅读器错误_Iphone - Fatal编程技术网

Iphone RSS阅读器错误

Iphone RSS阅读器错误,iphone,Iphone,我目前正在做一个应用程序,它使用来自的RSS提要。但是,我不断收到错误,无法从网站下载XML数据。谁能告诉我怎么了 @implementation Parser @synthesize items, responseData; @synthesize currentTitle; @synthesize currentDate; @synthesize currentSummary; @synthesize currentLink; @synthesize currentPodcastLink;

我目前正在做一个应用程序,它使用来自的RSS提要。但是,我不断收到错误,无法从网站下载XML数据。谁能告诉我怎么了

@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

您的错误与RSS解析方面完全无关。更重要的是,您甚至还没有粘贴完整的错误。您应该在
-connection:didFailWithError:
的实现中记录错误对象本身。这应该会给你一个通俗易懂的错误描述。

你的问题读起来很糟糕,请使用GDB控制台的Back Trace命令编辑你的问题到底在哪里崩溃。如果你想解析iPhone上的RSS,我建议你看一下。