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 中检测重定向
基础教程推荐
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
