Search code examples
iosdnsuiwebview

Scenarios in which NSURLErrorCannotFindHost can occur in iOS webview


I am an embedded programmer,but now am trying to analyze iOS logs for an issue where webview fails to load an URL. From the logs, I see the following

404230 (_:didStartProvisionalNavigation:)::Entry 
404230 (_:didStartProvisionalNavigation:)::Exit 
404250 (_:didFailProvisionalNavigation:withError:)::Entry
404250 (_:didFailProvisionalNavigation:withError:)::server with the specified hostname could not be found
404250 (_:didFailProvisionalNavigation:withError:)::Exit

It is observed that didFailProvisionalNavigation:withError is called within 20 milliseconds after didStartProvisionalNavigation with error as NSURLErrorCannotFindHost.

So following are my questions:

  1. Based on the timing between didStartProvisionalNavigation and didFailProvisionalNavigation:withError, I am starting to wonder if webview actually tried to resolve the domain name. Is this timing normal, what is the default DNS lookup timeout?
  2. In what other circumstances will this error happen?

Solution

  • When iOS webview tried to resolve the domain name, the DNS server returned Standard query response, Refused (Checked that in wireshark) which is why webview reported the error NSURLErrorCannotFindHost.

    Apparently since it is an DNS error, it invoked the callback _:didFailProvisionalNavigation:withError few milliseconds after _:didStartProvisionalNavigation. Had it been timeout, it might have taken longer.