rss阅读iphone/ipad app

Gab*_*iel 6 xml iphone rss xcode objective-c

我在为iPhone应用程序读取XML文件时出错.我的iPhone应用程序上有一个新功能,可以读取我的RSS源.一切看起来不错,但我有这个问题:

加载rss时出错.请检查您的Internet连接

这是我的代码:

- (BOOL) readRSS {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    [[NSURLCache sharedURLCache] setMemoryCapacity:0];
    [[NSURLCache sharedURLCache] setDiskCapacity:0];
    BOOL success = NO;
    NSXMLParser *parser = nil;
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://rss.domain.com/%@.xml", self.currentPage]];
    parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
    [parser setDelegate:self];
    [parser setShouldProcessNamespaces:NO];
    [parser setShouldReportNamespacePrefixes:NO];
    [parser setShouldResolveExternalEntities:NO];
    success = [parser parse];
    [parser release];
    [pool drain];
    return success;
}
Run Code Online (Sandbox Code Playgroud)

然后我有这个代码:

- (void) cleartbl:(NSInteger)type {
    [[[self rssParser] rssItems] removeAllObjects];
    [_tableView reloadData];
    if(type == 1) {
        UIAlertView *alert = [[UIAlertView alloc] 
                          initWithTitle:@"RSS Feed" 
                          message:@"Error while loading rss. Please check your Internet connection."
                          delegate:nil 
                          cancelButtonTitle:@"OK" 
                          otherButtonTitles: nil];
        [alert show];   
        [alert release];
    }
Run Code Online (Sandbox Code Playgroud)

然后我指定:

if([elementName isEqualToString:@"title"]){
    self.currentItem.title = self.currentItemValue;
}
Run Code Online (Sandbox Code Playgroud)

我的问题是什么,我错过了什么?

Boo*_*eus 12

提供的代码对我来说很好,我首先要做的是检查你的RSS是否有效.我想你这里有一个RSS问题.您可以使用RSS验证来确保一切都很好.

我建议清理你的RSS,保持简单,如果你只想显示新闻或文章使用文字中的字母和数字,并使用SEO友好的URL.

这将简化您从应用程序加载的数据,并避免出现特殊字符等错误.

尝试使用带有一个条目的简单RSS开始,您将看到您的代码是否有错误.

  • 神圣的废话,我花了最后6个小时来解决我的代码问题,这是我的RSS.你给的样品有效,谢谢 (7认同)