WKWebView catch HTTP error codes

后端 未结 1 1779
我在风中等你
我在风中等你 2021-01-07 19:42

When i return any http error from my page (currently 401, but i tried also with 404 and so on)

http://min60.com/__personal/e401.php

the delegate callbacks of

相关标签:
1条回答
  • 2021-01-07 20:02

    The key was to wait for the response and then inspect the object, no error is called on http code

    - (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler {
    
        if ([navigationResponse.response isKindOfClass:[NSHTTPURLResponse class]]) {
    
            NSHTTPURLResponse * response = (NSHTTPURLResponse *)navigationResponse.response;
            if (response.statusCode == 401) {
    
                // here we go
    
            }
    
        }
        decisionHandler(WKNavigationResponsePolicyAllow);
    }
    
    0 讨论(0)
提交回复
热议问题