简体   繁体   English

使用UIWebView专用API?

[英]Use UIWebView Private API?

I want to make a Browser like Safari with UIWebView, which can show the loading progress of the web page. 我想用UIWebView做一个像Safari这样的浏览器,它可以显示网页的加载进度。 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. 而且我在应用程序商店(http://itunes.apple.com/app/id349275540?&mt=8)上看到一个应用程序“ Downloads Lite-Downloader&Download Manager”可以做到这一点。 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. 但是似乎不可能通过UIWebView的公共API实现它,所以我想知道他是如何做到的。 Could you give me some tips about this? 您能给我一些提示吗?

There is no need for private API to do things like this. 不需要私有API来做这样的事情。

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 : 通过使用异步NSURLConnection,您可以获得想要下载的内容的预期大小:

-(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. 可以使用CFNetwork框架自定义用户代理。

看看这个app / blog:icab.de通用方法是制作NSProtocol的子类并捕获所有http / https请求,这将为您提供所需的一切。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM