在iOS中提取网址响应值

时间:2014-04-12 14:30:02

标签: ios webview

在我的应用程序中,我正在尝试在Web视图上加载特定的URL。网址已正确加载。当事务失败时,从Web视图响应返回的绝对URL是https://abc.xxx.com/check/resources/load.html#failed并且当它成功时返回的绝对URL是 https://abc.xxx.com/check/resources/load.html#SUCCESSFUL:1048:7771.00:INR:1397312651798

我在获取响应时遇到问题,就像我获得成功的标记一样,如何从响应中获取字符串SUCCESSFUL。如果响应成功或失败,我想执行条件检查。

1 个答案:

答案 0 :(得分:0)

您需要在UIWebView上设置委托。

然后使用UIWebViewDelegate方法-webView:shouldStartLoadWithRequest:navigationType:

创建Web视图时:

webView.delegate = self;

然后在视图控制器中添加包含Web视图的委托方法。

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { NSURL *url = request.URL; if ([url.host isEqualToString:@"abc.xxx.com"]) { NSString *fragment = url.fragment; // Do something with the fragment which is the bit after the # // Return NO if you don't want to load the URL } return YES; }