我在游戏中使用UIWebView
来显示客户支持表单。我注意到如果服务器返回503错误(从负载均衡器发送的http状态代码),我将无法关闭webview
有没有办法轻松获得此http状态?我可以进行一些设置,以便在http状态代码不是200时调用didFailWithError
吗?
加载代码
UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.frame];
NSURL *nsURL = [NSURL URLWithString:url];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:nsURL];
webView.opaque = YES;
webView.userInteractionEnabled = YES;
[webView loadRequest:request];
webView.delegate = self;
closableWebViewController = [[UIViewController alloc] init];
[closableWebViewController.view setFrame:self.view.frame];
[closableWebViewController.view addSubview:webView];
[self presentViewController:closableWebViewController animated:YES completion:nil];
此委托方法未被调用
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
NSLog(@"webview error %@",error);
if (closableWebViewController)
{
NSLog(@"closing webview");
[closableWebViewController dismissViewControllerAnimated:TRUE completion:^{
closableWebViewController = nil;
NSLog(@"webView closed");
}];
}
}