我正在使用MWFeedParser在我的应用程序中下载提要。到目前为止它工作正常 - 但是,我无法解析每篇文章的图像 URL。这是我目前的代码:
// MWFeedItem.h
NSData* firstImg;
@property (nonatomic, retain) NSData* firstImg;
MWFeedItem.m
add synthesize and dealoc
// RootViewController.m
- (NSString *)getFirstImage:(NSString *)htmlString{
NSScanner *theScanner;
NSString *text = nil;
theScanner = [NSScanner scannerWithString: htmlString];
// find start of tag
[theScanner scanUpToString: @"<img src=\"" intoString: NULL];
if ([theScanner isAtEnd] == NO) {
NSInteger newLoc = [theScanner scanLocation] + 10;
[theScanner setScanLocation: newLoc];
// find end of tag
[theScanner scanUpToString: @"\"" intoString: &text];
}
return text;
}
(void)feedParser:(MWFeedParser *)parser didParseFeedItem:(MWFeedItem *)item {
NSLog(@"Parsed Feed Item: “%@”", item.title);
NSString* str_imageUrl = [self getFirstImage:item.summary];
item.firstImg = [NSData dataWithContentsOfURL:[NSURL URLWithString:str_imageUrl]];
if (item) [parsedItems addObject:item];
}
我无法使用此代码查看图像,我不知道为什么。