问题描述
我很好奇是否有一种方法可以检测 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 中的页面更改的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)