在UIWebView中使用自定义URL方案 [英] Using a custom URL scheme with UIWebView

查看:123
本文介绍了在UIWebView中使用自定义URL方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个黑盒子容器。我喜欢黑盒子,它们很好地混淆了东西。

I have a black box container. I love black boxes, they obfuscate things so well.

这个黑盒子是一个加密的zip(有点像),里面有一些html文件(这是简短的,不太难解释,版本)。

This black box is an encrypted zip (sort of) and has inside some html files (this is the short, not so painful to explain, version).

这些文件需要在UIWebView中显示。现在,简单的方法,解密,解压缩到文件系统,从文件系统加载文件。这很好,除了黑盒包含秘密的东西,并且不能只放在文件系统上,甚至不是一秒钟,所以,我做了一个实际上流式传输盒子内容的C库(直接开箱即用) 。

Those files need to be displayed in an UIWebView. Now, the easy way to do it, decrypt, unzip to filesystem, load file from filesystem. That's good, except, the black box contains secret stuff, and can't just lay around on the filesystem, not even a sec, so, I made a C library that actually streams the contents of the box (directly out of the box).

现在,我有这种流媒体功能,并且必须以某种方式使其与UIWebView一起使用。我想到的第一件事就是使用一个迷你本地HTTP服务器,UIWebView可以在其中发送请求。然后我会自己管理请求并使用我已经完成的流式lib返回UIWebView所需的内容。我认为这样可行,但我认为迷你HTTP服务器可能会有点过分。

Now, I have this streaming capability and have to somehow make it work with UIWebView. First thing that comes in my mind would be to use a mini local HTTP server where the UIWebView can sent its requests. I would then manage the requests myself and return the contents the UIWebView requires using the streaming lib I've done. That would work I suppose well, but I think a mini HTTP server would somehow, maybe, be a little bit of a overkill.

所以,我想知道,有没有另一种干扰UIWebView和文件系统的方法?也许使用自定义架构?喜欢myschema://?每当UIWebView向myschema发出请求时://myfile.html我会以某种方式干扰并返回它需要的数据?

So, I was wondering, is there another way to interfere between UIWebView and the filesystem? Maybe using a custom schema? Like myschema://? And every time the UIWebView makes a request to myschema://myfile.html I would somehow interfere and return the data it needs?

这样的想法是否可行?我应该从哪里开始?也许NSURLRequest?

Is such a idea viable? Where should I look to start from? Maybe NSURLRequest?

编辑:我发现了这个: iPhone SDK:从自定义URL方案加载资源。听起来不错,浏览器将如何知道请求的大小,类型(xml / binary / xhtml)以及HTTP在其标题中放置的所有信息?

I found this: iPhone SDK: Loading resources from custom URL scheme. It sounds good, however, how will the browser know the size of the request, the type (xml/binary/xhtml) and all the info HTTP puts in its header?

推荐答案

创建一个自定义的 NSURLProtocol 子类并注册它以便它处理HTTP请求。这将允许您处理来自 UIWebView 的请求但是您认为合适,包括从库中提供数据。您可以通过查看 RNCachingURLProtocol 来检查执行磁盘缓存请求的实现,以允许脱机浏览。我个人使用我编写的自定义 NSURLProtocol 子类来处理将一些javascript代码注入到 UIWebView 中加载的页面中,它的效果非常好。

Create a custom NSURLProtocol subclass and register it so it will handle the HTTP requests. This will allow you to handle the requests that come from the UIWebView however you see fit, including supplying the data from your library. You can examine an implementation of one that performs disk caching of requests to allow offline browsing by looking at RNCachingURLProtocol. I personally use a custom NSURLProtocol subclass that I wrote to handle injecting some javascript code into pages that are loaded in the UIWebView, and it works very well.

这篇关于在UIWebView中使用自定义URL方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆