UIWebView get favicons - ios

How can I get favicons from websites in ios UIWebView, like it is possible in android.
Maybe my question are idiotic, but I can't find anything.

You can get favicon of any website using its url string.Lets take an example in which we're trying to get favicon of 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];
This method of getting favicon worked nicely for me.
All the best.

Related

Problems on downloading html page through NSData

I am currently trying to download the html code of a page for an app I am working on. For some reason when I try to download the code through
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:#"https://www.fedex.com/fedextrack/?tracknumbers=%#,#"Tracking#"]]];
I dont get the right HTML code however. When I set up the same load request through a UIWebView have it load then then get the HTML code from stringByEvauluatingJavaScript:#"document.body.innerhtml" I do get the right one.
My question is, how do I make the dataWithContentsOfURL work and get the right code?

Getting Image URLs in a Web Directory

I want to get URLs of all images or lets say "JPEG" files in a web directory (www.abcde.com/images). I just want their URLs in an array.. I couldnt manage that. Could u pls help me with this?
Thanks in advance..
Assuming you have access to an index file you could simply load via NSURL the whole html file and cut out the link lines. This however will not work (or hardly work) when you want to search ("spider or crawl") for links in more complex documents. On iOS i would suggest you use the simple, yet quite powerfull "hpple" framework (https://github.com/topfunky/hpple). It is used to parse html. You can search with it for certain html elements, such as <a href...> constructs.
a sample with hpple could looks like this:
NSURL *url = [NSURL URLWithString:#"whatver.com/images"];
NSData *data = [NSData url];
TFHpple *hppleParser = [TFHpple data];
NSString *images = #"//img"; // grabbs all image tags
NSArray *node = [hppleParser searchWithXPathQuery:images]
find a bigger example at http://www.raywenderlich.com/14172/how-to-parse-html-on-ios
Create a server side script(eg php) which gives you a list of all images in that directory as xml or json. From iOS send a request to that script get the xml or JSON parse it and use the image urls.

PDF Text Extraction in iOS [duplicate]

I'm displaying locally stored pdf in my iPad application. Here's the code:
NSString *path = [[NSBundle mainBundle] pathForResource:#"About Downloads" ofType:#"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[pdfWebView loadRequest:request];
Now, by default, you can't copy text or images from the PDF which is rendered by the UIWebView. Is there a way to let users copy text and/or images out of pdf?
I'm not familiar with CATitledLayer, so i'm just wondering if it can help in this case?
There's no simple answer to this. PDF's are nested dictionaries composed of more dictionaries & arrays. You'll have to dig into CGPDFDocument. Voyeur is an excellent tool to use while digging around in PDF's. Reader is a good suggested starting point for rendering PDF's.
To get at the text in a PDF Document, I use PDF Kitten (https://github.com/KurtCode/PDFKitten). It works quite well, but as the author notes, is incomplete and does not support all font types.

UIImage: How to get website tab icon

I'm developing an RSS Reader and I need to get the favicon for each feed. For example, if my feed is google.com, I'd like to get the "G" icon and put it into a UIImage or something. Any ideas on how to achieve this?
The easiest way to go would be 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 would just have to replace the domain where you want to query your icon.
If you want the favicon, try calling this URL: http://www.google.com/s2/favicons?domain=<rss_domain> from within your app:
[NSURLConnection connectionWithRequest:
[NSURLRequest requestWithURL:
[NSURL URLWithString:#"http://www.google.com/s2/favicons?domain=google.com"]]
delegate:self];
Otherwise, an RSS channel's metadata has an optional element, <image>, 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 will typically be larger than a site's favicon, and likely not-square, but with some clever cropping and scaling, it can work as an icon if a feed's favicon isn't available.
If you save the image to your desktop,
1) drag image into xcode
2)Go to interface builder
3)Go to the identity inspector after selecting the UIImage
4)Under the image drop down box, select the name of your image.
Hope that helps!

Reading text and images from a pdf document in iOS

I'm displaying locally stored pdf in my iPad application. Here's the code:
NSString *path = [[NSBundle mainBundle] pathForResource:#"About Downloads" ofType:#"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[pdfWebView loadRequest:request];
Now, by default, you can't copy text or images from the PDF which is rendered by the UIWebView. Is there a way to let users copy text and/or images out of pdf?
I'm not familiar with CATitledLayer, so i'm just wondering if it can help in this case?
There's no simple answer to this. PDF's are nested dictionaries composed of more dictionaries & arrays. You'll have to dig into CGPDFDocument. Voyeur is an excellent tool to use while digging around in PDF's. Reader is a good suggested starting point for rendering PDF's.
To get at the text in a PDF Document, I use PDF Kitten (https://github.com/KurtCode/PDFKitten). It works quite well, but as the author notes, is incomplete and does not support all font types.

Resources