iOS UIWebView 页面加载可观察性 [英] iOS UIWebView page load observability
问题描述
我想确定的是,在 UIWebView
中何时完成页面加载.我知道 didStartLoad
/didFinishLoad
在此处概述 并且它有点适合我,但我对此不太有信心.它已经长出了一些毛茸茸的 ifs
并且在 Javascript 决定与 document.location
对话时仍然表现得很奇怪.我不清楚以下几点:
I would like to know for sure, when a page load is finished in UIWebView
. I am aware of the "refcounting" approach between didStartLoad
/didFinishLoad
outlined in here and it kinda-sorta works for me, but i don't feel very confident about it. It has grown some hairy ifs
and still acts strangely when Javascript decides to talk into document.location
. I am unclear namely about the following:
UIWebViewDelegate
对于它应该处理的所有功能,非常简洁并且具有 旁边没有文档.任何人都可以确认didStartLoad
/didFinishLoad
真的只为frames"调用,这意味着很可能是frameset/frame"和iframe"?- 如何区分上述 DOM 引起的负载和请求重定向(也产生事件)?
- 我的观察是每个
didStartLoad
前面都有shouldStartLoadWithRequest
,重定向除外.这是一种可靠的行为吗? - 我是否遗漏了什么,或者无法知道特定
didStartLoad
是什么请求发起的?因为给定的唯一上下文的[[webView request] URL]
总是返回相同的 URL,即 UIWebView 最初被要求加载的那个.
UIWebViewDelegate
for all the power it should handle, is very terse and has next to none documentation. Can anyone confirm thatdidStartLoad
/didFinishLoad
is really called only for "frames" which means most probably "frameset/frame" and "iframe" ?- how can i distinguish the above DOM-induced loads from request redirections (which produce the events too)?
- my observation is that each
didStartLoad
is preceded withshouldStartLoadWithRequest
, except redirections. Is this a dependable behavior? - am i missing something, or is there no way of knowing what request has originated the particular
didStartLoad
? Because[[webView request] URL]
of the only context given, is always returning the same URL, that is the one which UIWebView was asked to load initially.
推荐答案
使用 shouldStartLoadWithRequest
中的 UIWebViewNavigationType
至少可以识别当前加载是来自用户点击还是页面中发生的任何其他事情.知道页面何时确定加载是无济于事的,但是您可以在用户触发新代码之前启动一些代码.这可能会有所帮助,具体取决于您必须在两页之间执行的任务的性质.
With UIWebViewNavigationType
from shouldStartLoadWithRequest
at least you can identify if the current loading comes from a user click or anything else which happened whithin the page. It can't help to know when the page is definitely loaded, but you can launch some code before a new one is triggered by the user. It may help, depending on the nature of task you have to do between two pages.
这篇关于iOS UIWebView 页面加载可观察性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!