How to detect redirect in a UIWebView(如何在 UIWebView 中检测重定向)
问题描述
我在我的应用程序中使用 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 中检测重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 UIWebView 中检测重定向


基础教程推荐
- :hover 状态不会在 iOS 上结束 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
- Android文本颜色不会改变颜色 2022-01-01
- 固定小数的Android Money Input 2022-01-01
- 如何使 UINavigationBar 背景透明? 2022-01-01
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01