需要过滤某些UIWebView请求并将它们加载到不同的UIWebViews中 [英] Need to filter certain UIWebView requests and load them in different UIWebViews

查看:77
本文介绍了需要过滤某些UIWebView请求并将它们加载到不同的UIWebViews中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

某些背景

我有一个带三个UIWebViews的iPhone应用程序,每个UIWebViews用于显示不同类型的页面。 (内容是专门为此目的而设计的,它们不是真实的网页。)每个特定的Web视图都有相关的链接。例如,在WV1中点击的链接可能需要在WV2中加载,因为它是WV2样式的链接。 (这些Webview位于一个分页的UIScrollView中,我可以使用它滚动到当前正在加载的Webview。我可以根据路径来确定将哪个URL加载到哪里。)

I have an iPhone app with three UIWebViews, each used to show a different type of page. (The content is specifically designed for this purpose, they're not real web pages.) There are links associated with each specific web view. For example, a link tapped in WV1 might need to load in WV2 because it's a WV2-style link. (The webviews are in a paged UIScrollView, which I use to scroll to the currently loading webview. I can tell which URL loads where based on it's path.)

对我来说,有一个UIWebView委托可以响应所有URLRequest(通过 webView:shouldStartLoadWithRequest:navigationType ),并以某种方式决定将哪个加载到哪里。

It makes sense to me to have a single UIWebView delegate that responds to all URLRequests (via webView:shouldStartLoadWithRequest:navigationType) and somehow decides which should load where.

我要加载到Web视图中的HTML并不是直接从页面获取的。我做类似 [NSDictionary dictionaryWithContentsOfURL:] 的操作来获取对象,其中一部分是实际的HTML。 (另外,这可能来自网络或本地缓存。)

The HTML I want to load in the webview isn't fetched directly from a page. I do something like [NSDictionary dictionaryWithContentsOfURL:] to get the object, part of which is the actual HTML. (Additionally, this might come from the network or a local cache.)

问题

我需要在一个UIWebView中取消一个请求,然后将一些任意数据加载到另一个UIWebView中。我应该如何进行后续加载,以使其绕过我的拦截?

I need to cancel a request in one UIWebView and then load some arbitrary data into another. How should I be doing the subsequent load, so that it bypasses my interception?

我应该通过webview委托方法停止所有对所有NSURLRequest的拦截,然后发送一个新的NSURLRequest,实际将其加载到正确的webview?我当时以为我可以将NSURLRequest子类化,因此我可以将原始请求与我的篡改请求区分开。但是再次,我不想直接提出NSURLRequests,我想获取一个NSDictionary并将其值之一用作HTML。

Should I stop all intercept all NSURLRequests via the webview delegate method, then send a new NSURLRequest, that will actually get loaded, to the correct webview? I was thinking I'd subclass NSURLRequest so I'd be able to tell original requests separate from my doctored requests. But again, I don't want to make straight NSURLRequests, I want to fetch an NSDictionary and use one of it's values as the HTML.

我看到了这个文章有关过滤哪些内容加载到UIWebView中,但是我不正是我想要的。

I saw this article on filtering what loads in a UIWebView, but I don't think that's exactly what I want.

我正在尝试通过 URL加载系统概述,但还有很多。

I'm trying to work my way through the URL Loading System Overview, but there's a lot there.

推荐答案

最后使用自定义URL方案来标识要加载的请求和要处理的请求。

Ended up using custom URL schemes to identify the requests that I wanted to load vs. the ones I wanted handled.

这篇关于需要过滤某些UIWebView请求并将它们加载到不同的UIWebViews中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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