Get notified about a page change in UIWebView(获取有关 UIWebView 中的页面更改的通知)
问题描述
我很好奇是否有一种方法可以检测 UIWebView 内显示网站的变化.在我正在开发的应用程序中,我们使用 UIWebView 来呈现部分功能,这些功能基本上是用户需要遵循的几个步骤.但是,在这些步骤结束时,我需要识别一个特定页面,然后应用程序需要显示不同的视图.
I'm curious if there's a way to detect a change of the displayed website inside a UIWebView. In an app I'm working on we're using a UIWebView to present a part of the functionality which are basically a few steps the user needs to follow. However, the will be a specific page at the end of these steps that I need to identify and after which the app needs to display a different view.
不幸的是,UIWebViewDelegate 似乎没有解决问题.
Unfortunately the UIWebViewDelegate doesn't seem to do the trick.
推荐答案
如果用户步骤在不同的页面上是分开的,而UIWebView需要加载不同的步骤,这确实应该可以委托方法.
If the user steps are separated on different pages, and the UIWebView needs to load the different steps, this should indeed be possible with the delegate methods.
在这个例子中,我们说用户经历了 3 个步骤,分别命名为 step1.htm、step2.htm,最后是 step3.htm.此代码将检测用户何时到达第三步也是最后一步.
In this example, we say that the user goes through 3 steps, named step1.htm, step2.htm and finally step3.htm. This code will detect when the user reaches the third and final step.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSString *URLString = [[request URL] absoluteString];
if ([URLString isEqualToString:@"http://www.example.com/step3.htm"]) {
// The user reached step 3!
}
return YES;
}
请注意,使用 absoluteString 方法可能不是找出用户浏览位置的最佳方法.看看query、path、parameterString等...
Note that using the absoluteString method might not be the best way to find out where the user is browsing. Take a look at query, path, parameterString, etc...
这篇关于获取有关 UIWebView 中的页面更改的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:获取有关 UIWebView 中的页面更改的通知
基础教程推荐
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
