如何从另一个网站(如 osx Dashboard)创建功能的 UIWebView

发布于 2024-12-20 05:30:21 字数 483 浏览 2 评论 0 原文

您好,我想使用当地气象服务网站的信息制作个人雨雷达应用程序。 我只想在我的应用程序中显示降雨雷达,您可以在此链接中看到

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

我想知道是否可以调用图像并创建我的自己的小播放器。我使用谷歌源查看器并找出代码的哪些部分包含图像,但我只是不确定如何使用它们。

在此处输入图像描述 在此处输入图像描述

任何帮助将不胜感激

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终难遇 2024-12-27 05:30:21

您还有大量的工作要做,但这将是一次很好的学习经历。

首先,您需要获取 HTML 形式的网页内容。 Apple 有一个教程演示如何使用 NSURLRequestNSURLConnection 来执行此操作:

URL 加载系统编程指南

从该链接获取数据后,您可以跳过创建NSString,然后直接跳转到 XML 解析器。不过,如果您确实需要创建字符串用于其他用途,则可以使用:

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

一旦获得 HTML 数据,您就可以使用 XML 解析器来查看 HTML 并找到要显示的图像的 URL:

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

< code>NSXMLParser 类引用将有助于确定如何遍历 HTML:

NSXMLParser 类参考

一次你已经解析了 URL 并拥有了它们,你实际上可以使用 URL 创建 NSImage 对象,它们将从网页延迟加载:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文