Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIWebview:如果web视图中任何已加载的链接无法打开,如何通知UIViewController_Ios_Iphone_Objective C_Uiwebview_Delegates - Fatal编程技术网

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视图
  • 错误:加载过程中发生的错误
可用性:在iOS 2.0及更高版本中提供

记住,你应该:

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;