2013-06-22 15 views
0

我正在使用MWFeedParser在我的應用中下載源。到目前爲止它工作正常 - 但是,我無法解析每個文章的圖像URL。這是我目前擁有的代碼:在用MWFeedParser解析的Feed中查看圖像

// 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];  
} 

我不能使用此代碼查看圖像,我不知道爲什麼。

+0

您需要檢查str_imageUrl是完整的URL還是相對於網站本身。您將需要一個完整的URL來下載圖像。 –

+0

可能重複的[MWFeedParser - RSS與圖像\ [XCODE \]](http://stackoverflow.com/questions/15254500/mwfeedparser-rss-with-images-xcode) – Berendschot

回答

0

嘗試CXFeedParser。它來自MWFeedParser,並且包含每個feedItem的圖像的NSArray。

+2

我得到的錯誤說,某些庫是失蹤。 –