使用 UIWebView 私有 API?
我想用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不需要私有 API 来做这样的事情。
以进度指示器为例。通过使用异步 NSURLConnection,您可以获得要下载的内容的预期大小:
然后您只需与到目前为止下载的数据量进行比较即可。
自定义用户代理可以使用 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 :
Then you simply compare with the amount of data you downloaded so far.
Customizing User Agents can be done with CFNetwork framework.
看看这个应用程序/博客: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.