ios - 检测 WKWebview 何时无法处理请求
<p><p>我有以下代码</p>
<pre><code>NSURL *nsurl = ;
NSMutableURLRequest *request = ;
WKWebViewConfiguration *config = ;
WKWebView *wv = [ initWithFrame:[ bounds] configuration:config];
wv.navigationDelegate = self;
</code></pre>
<p>还有代表:</p>
<pre><code>- (void)webView:(WKWebView *)webView
decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse
decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler {
...
}
</code></pre>
<p>工作正常,当无法加载(404 等)时,我可以捕获错误。但是当 <code>nsurl</code> 是 WKWebView 甚至无法处理的东西时,我该如何捕捉错误?</p>
<p>例如:</p>
<pre><code>NSURL *nsurl = ;
</code></pre>
<p>将导致没有调用委托(delegate)方法的空白页面。我该如何处理检测到这个错误? (我已经检查过这个 <a href="https://stackoverflow.com/questions/5370009/iphone-sdk-check-validity-of-urls-with-nsurl-not-working" rel="noreferrer noopener nofollow">iPhone SDK: Check validity of URLs with NSURL not working?</a> 但我想知道有没有比正则表达式更好的东西?)</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>你可以试试看是否可以这样请求url:</p>
<pre><code>NSURL *nsurl = ;
if(]){
NSLog(@"URL can be loaded");
}else{
NSLog(@"URL cannot be loaded");
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 检测 WKWebview 何时无法处理请求,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/37897337/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/37897337/
</a>
</p>
页:
[1]