获取有关 UIWebView 中的页面更改的通知 [英] Get notified about a page change in UIWebView

查看:15
本文介绍了获取有关 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.htmstep2.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 方法可能不是找出用户浏览位置的最佳方法.看看querypathparameterString等...

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 中的页面更改的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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