[英]UIWebView get http status code from loaded page
我在游戲中使用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");
}];
}
}
您很難達到目標,但是這里有一個很好的技巧:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.