问题描述
我在我的应用程序中使用 UIWebView 作为嵌入式浏览器.我遇到的问题是跟踪应该在 URL 栏中显示的 URL.
I am using a UIWebView as an embedded browser within my app. The problem I have is tracking the URL that should be displayed in the URL bar.
在进行 Google 搜索时,结果页面通常会生成如下链接:
When doing a Google search, the results page often generates links like this:
http://www.google.com/url?sa=t&source=web&cd=1&ved=0CC4QFjAA&url=http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FDog&rct=j&q=dogs&ei=27XeTc6RFIWEvAO858DHBQ&usg=AFQjCNGkEDcWzea4pSlurHhcuQfqFcp_pw
当用户点击这个链接时,UIWebView先上报这个链接,然后是shouldStartLoadWithRequest:navigationType:
中的重定向链接.
When the user clicks this link, the UIWebView first reports this link and then the redirected link in shouldStartLoadWithRequest:navigationType:
.
我怎么知道这是一个重定向,而不是为页面上的图像或其他元素加载的一些补充站点?就目前而言,我的 URL 栏在上面的示例中显示来自 Google 的长链接,而不是更新到 Wikipedia URL.
How can I tell this is a redirect as opposed to some supplementary site being loaded for images or other elements on the page? As it stands my URL bar is displaying the long link from Google in the above example rather than updating to the Wikipedia URL.
推荐答案
你能做的最好的事情就是观察 webView:shouldStartLoadWithRequest:navigationType:
委托方法.我假设重定向属于 UIWebViewNavigationTypeOther
.
The best you can really do is observe the webView:shouldStartLoadWithRequest:navigationType:
delegate method. I assume that redirects fall under UIWebViewNavigationTypeOther
.
这篇关于如何在 UIWebView 中检测重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!