Question

I was wondering if anyone has created a reader app for iOS that allows the user to view a webpage in a native environment rather than in a webview? I'm trying to use a screen scrape method, but I'm having trouble entering in the url so that the page displays.

Was it helpful?

Solution

I am not sure by what you mean when you say viewing a webpage in a native environment, i'm guessing you want to strip the webpage of everything except select things that you want to display? You can do this by downloading the web page itself, in a simplified version, downloading index.html from a web server. You would then have to create some type of a parser that would go through the html file and grab things that you would like to show like things that are between <p></p> tags, which would be body paragraphs and so forth. The parser would return an array of objects, for this simplified example we will say an array of strings, each string holds the body of text that was between different <p> tags. You would then dynamically create textfields or a textfield and format the content as you wish and display it as you want.

Here is some code to get you started:

NSURL *url = [NSURL URLWithString:@"http://www.google.com"]
NSString *webPageString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:NULL];

Excuse any typo in that code, i free hand wrote it on a pc so a method name might be slightly wrong or capitalized wrong if you copy it in. You can then experiment on your favorite website by stripping parts of it that you want and displaying them in an app as you wish.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top