C.Johns
C.Johns

Reputation: 10245

How to create a UIWebView of a feature from another website (Like osx Dashboard)

Hi there I am wanting to make a personal rain radar application with information from my local weather service website. I would like to have only the rain radar display in my application that you are able to see in this link

http://www.metservice.com/national/maps-rain-radar/rain-radar/auckland

I am wondering if it is possible to call the images from and create my own little player. I used googles source viewer and have figured out which parts of the code contain the images but I'm just not sure how I could make use of them.

enter image description here enter image description here

any help would be greatly appreciated

Upvotes: 1

Views: 165

Answers (1)

Craig Otis
Craig Otis

Reputation: 32094

You've got a fair amount of work ahead of you, but this would be a good learning experience.

First, you'll need to obtain the contents of the web page in HTML form. Apple has a tutorial demonstrating how to use NSURLRequest and NSURLConnection to do so:

URL Loading System Programming Guide

Once you have obtained the data from that link, you can skip creating an NSString, and just jump right into an XML parser. Though, if you do need to create a string for other uses, you can use:

NSString *stringWithHTMLData =
            [[NSString alloc] initWithData:webPageData
                              encoding:NSStringUTF8Encoding];

Once you have the HTML data, you can use an XML parser to look through the HTML and find the URLs of the images you want to display:

NSXMLParser *parser = [[NSXMLParser alloc] initWithData:webPageData];

The NSXMLParser class reference would be of help in determining how to traverse the HTML:

NSXMLParser Class Reference

Once you have parsed the URLs and have them, you can actually create the NSImage objects with the URLs, and they will lazily load from the web page:

NSURL *firstImageURL = ...;
NSImage *image = [[NSImage alloc] initByReferencingURL:firstImageURL];
// Do something with the image, like adding it to a view somewhere

Upvotes: 1

Related Questions