Need to filter certain UIWebView requests and load them in different UIWebViews

泄露秘密 提交于 2019-12-25 01:46:02

问题


Some Background

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.)

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.

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.)

The Question

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?

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.

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

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


回答1:


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



来源:https://stackoverflow.com/questions/2358957/need-to-filter-certain-uiwebview-requests-and-load-them-in-different-uiwebviews

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!