如何在UIWebView中检测重定向 [英] How to detect redirect in a UIWebView

查看:415
本文介绍了如何在UIWebView中检测重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用UIWebView作为我的应用程序中的嵌入式浏览器。

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的长链接,而不是更新到维基百科的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中检测重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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