Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

preiostd

macrumors newbie
Original poster
Oct 27, 2012
11
0
I am using MWFeedParser to download feeds in my app. So far it's working fine - however, I donnot know how to retrive image from feed and view in the detailed article??
 
I am using MWFeedParser to download feeds in my app. So far it's working fine - however, I donnot know how to retrive image from feed and view in the detailed article??


Right now MWFeedParser only lets you get particular things from the feed

MWFeedItem:
item.title (NSString)
item.link (NSString)
item.date (NSDate)
item.updated (NSDate)
item.summary (NSString)
item.content (NSString)
item.enclosures (NSArray of NSDictionary with keys url, type and length)
item.identifier (NSString)

In most cases the images are in the form of links inside item.content.
So you will have to parse out the links on your own and download the images for them.

I started using that parser but since it didnt do images already I ended up making my own using AFNetworking, SDWebImage and using a JSON feed on Wordpress (but that requires your feed to be JSON instead of RSS which the format can be different depending on the site/feed)
 
Thanks 4 r replay :)
Itried to parse each article for it's image URL. This is the code I have currently:
Code:
// MWFeedItem.h

NSData* firstImg;
@property (nonatomic, retain) NSData* firstImg;
MWFeedItem.m
add synthesize and dealoc


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



but still I can't view the image:(
 
Does your function getFirstImage: even return a link to an image?


I would also put that if (item) line at the top of its function so you arent trying to get a link from a bad item.


Theoretically it should work, though later i would change the loading image to something more background
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.