I was tasked to build a simple RSS reader to read some RSS feed from online.
Recently I start to use AFNetworking, an amazing framework for all networking/web library.
I found this third-party library: BlockRSSParser which was based on the AFNetworking, the coding of RSSParser take less than 10 lines.
//MAKE Request to server and retrieve RSS feed
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:k_URL]];
[RSSParser parseRSSFeedForRequest:request success:^(NSArray *feedItems) {
//Do Something
} failure:^(NSError *error) {
//SHOW Error
}];
and this will parse RSS feed and return as feedItems As an NSArray.
The only problem I encountered is when I try to parse feed with content-type of “application/rss+xml”, I got an error instead of success. Prompt as unsupported content type. To fix this issue, I added “application/rss+xml” into acceptableContentTypes in AFXMLRequestOperation.m. The output look like this:
+ (NSSet *)acceptableContentTypes {
return [NSSet setWithObjects:@"application/xml", @"text/xml", @"application/rss+xml", nil];
}
