Ios UIWebview:如果web视图中任何已加载的链接无法打开,如何通知UIViewController
我有一个Ios UIWebview:如果web视图中任何已加载的链接无法打开,如何通知UIViewController,ios,iphone,objective-c,uiwebview,delegates,Ios,Iphone,Objective C,Uiwebview,Delegates,我有一个UIWebView控制器,我正在其中加载一个Web应用程序。如果web应用程序中的任何链接无法打开,我只需要通知UIViewController特定链接无法打开,因此我需要显示警报框。你们能在这方面指导我吗??任何帮助都将不胜感激。提前谢谢 您可以使用以下UIWebViewdelegate方法 - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error 在视图控制器中编写以下命令 在viewdid
UIWebView
控制器,我正在其中加载一个Web应用程序
。如果web应用程序中的任何链接无法打开,我只需要通知UIViewController
特定链接无法打开,因此我需要显示警报框。你们能在这方面指导我吗??任何帮助都将不胜感激。提前谢谢 您可以使用以下UIWebView
delegate方法
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
在视图控制器中编写以下命令 在viewdidload中
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receivefailedNotification:)
name:@"failedNotification"
object:nil];
- (void) receivefailedNotification:(NSNotification *) notification // this will trig automatically once we provide info to it in webviewcontroller
{
NSDictionary *userInfo = notification.userInfo;
}
在webviewcontroller中
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
NSLog(@"erroe");
NSDictionary *userInfo = [NSDictionary dictionaryWithObject: erroe forKey:@"OauthoKey"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"failedNotification"
object:self userInfo:userInfo];
}
通常情况下,苹果会为所有这些任务实施代理: 您可以使用:
webView:didfailloadwitheror:
如果web视图加载帧失败,则发送
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
参数
- webView:未能加载帧的web视图
- 错误:加载过程中发生的错误
yourWebView.delegate = self
及
h
@界面ViewController:UIViewController
或者,m
@界面视图控制器()
UIWebview
加载请求失败时调用
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
您可以从UIWebview
获取失败的链接,如下所示:
在此方法中,使用此代码获取失败的url
NSString *strFailedUrl = UIWebviewObj.request.url.absoluteString;
相应地通知您的UiviewController
或显示警报@Gabriel.masana:对不起,我实际上在找其他东西。到目前为止,我问的问题,我的想法是从这么多的答案。一定会投票…-)
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
NSString *strFailedUrl = UIWebviewObj.request.url.absoluteString;