UIImage: how to get website tab icon

I am developing an RSS reader and I need to get an icon for each feed. For example, if my channel is google.com, I would like to get a ā€œGā€ badge and put it in UIImage or something else. Any ideas on how to achieve this?

+6
ios favicon uiimageview rss-reader
source share
3 answers

The easiest way is to use Google:

NSString *myURLString = @"http://www.google.com/s2/favicons?domain=www.stackoverflow.com"; NSURL *myURL=[NSURL URLWithString: myURLString]; NSData *myData=[NSData dataWithContentsOfURL:myURL]; UIImage *myImage=[[UIImage alloc] initWithData:myData]; 

That should work.

You just need to replace the domain in which you want to request your icon.

+19
source share

If you need an icon, try calling this URL: http://www.google.com/s2/favicons?domain=<rss_domain> from your application:

 [NSURLConnection connectionWithRequest: [NSURLRequest requestWithURL: [NSURL URLWithString:@"http://www.google.com/s2/favicons?domain=google.com"]] delegate:self]; 

Otherwise, the RSS feed metadata has an optional <image> element, which is described here: http://www.rssboard.org/rss-specification#ltimagegtSubelementOfLtchannelgt

For example:

 <channel> <language>en-us</language> <title>Scientific American - News</title> <image> <title>Scientific American</title> <link>http://www.scientificamerican.com</link> <width>144</width> <url> http://www.scientificamerican.com/media/logo/SAlogo_144px.gif </url> <height>45</height> </image> ... 

This image is usually larger than the site icon, and probably not a square, but with some smart cropping and scaling, it can work as an icon if a fixed icon is not available.

+3
source share

If you save the image to your desktop,

1) drag the image into xcode 2) Go to the interface builder 3) Go to the identity inspector after choosing UIImage 4) In the image drop-down list, select the name of your image.

Hope this helps!

-7
source share

All Articles