使用 UIWebView 私有 API?

发布于 2024-11-27 20:28:26 字数 286 浏览 5 评论 0原文

我想用 UIWebView 制作一个像 Safari 这样的浏览器, 可以显示网页的加载进度。 我看到一个应用程序“Downloads Lite - 下载器和下载管理器”在应用程序商店出售 (http://itunes.apple.com/app/id349275540?&mt=8) 可以做到这一点。 它还可以定制请求的User Agent, 甚至可以获取响应头的“内容类型”来决定是否需要下载。

但使用 UIWebView 的公共 API 似乎不可能实现这一点, 所以我想知道他是怎么做到的。 你能给我一些关于这方面的建议吗?

I want to make a Browser like Safari with UIWebView,
which can show the loading progress of the web page.
And I saw an app "Downloads Lite - Downloader & Download Manager" selling in app store
(http://itunes.apple.com/app/id349275540?&mt=8) that can do this.
It also can customize User Agent of request,
even get "content type" of Response Header to decide whether it's needed to be downloaded.

But it seems that it's impossible to make it happen with the public APIs of UIWebView,
so I'm wondering how he did that.
Could you give me some tips about this?

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

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

发布评论

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

评论(2

逆流 2024-12-04 20:28:26

不需要私有 API 来做这样的事情。

以进度指示器为例。通过使用异步 NSURLConnection,您可以获得要下载的内容的预期大小:

-(void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response
{
    [response expectedContentLength];
}

然后您只需与到目前为止下载的数据量进行比较即可。

自定义用户代理可以使用 CFNetwork 框架来完成。

There is no need for private API to do things like this.

You take a progress indicator for example. By using asynchronous NSURLConnection you can get the size of the expected size of the content you want to download :

-(void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response
{
    [response expectedContentLength];
}

Then you simply compare with the amount of data you downloaded so far.

Customizing User Agents can be done with CFNetwork framework.

看透却不说透 2024-12-04 20:28:26

看看这个应用程序/博客:icab.de
一般方法是创建 NSProtocol 的子类并捕获所有 http/https 请求,这将为您提供您想要的一切。

have a look at this app/blog: icab.de
General approach is to make subclass of NSProtocol and catch all http/https request, that gives you all you want.

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