NSURLConnection Error Code -1100

Hello,


I am trying to load content into UIWebView, and when testing in the simulator all I get is a white screen and the following error in the console:


NSURLConnection finished with error - code -1100


Can anybody help? My current Swift Code is:


class ViewController: UIViewController {
    @IBOutlet weak var webView: UIWebView!
  
    override func viewDidLoad() {
        super.viewDidLoad()
      
        webView.allowsInlineMediaPlayback = true;       
        webView.mediaPlaybackRequiresUserAction = false;
      
        webView.loadRequest(URLRequest(url: URL(fileURLWithPath: Bundle.main.path(forResource: "www/index", ofType: "html")!)))
      
        let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView
        statusBar?.backgroundColor = UIColor.clear
      
    }
}


Just to clarify, this code usual works for me. Many thanks.

Error -1100 is

NSURLErrorFileDoesNotExist
, which pretty much means what it says on the tin. It’s hard to say exactly what’s going on here but I have a bunch of concerns:
  • UIWebView, while not deprecated, has effectively been replaced by WKWebView. Why are you not using that?

  • WKWebView has a specific API for loading local content, namely,

    loadFileURL(_:allowingReadAccessTo:)
    . That API makes this whole process much more reliable.
  • The way you’re building your URL is kinda wonky:

    • It’s better to work in ‘URL space’ and thus start with

      url(forResource:withExtension:)
      rather than
      path(forResource:ofType:)
      .
    • You want to get the URL for

      www
      and then create a relative URL to
      index.html
      within that. That will ensure that relative references in the HTML go to the right place.

I recommend that you start by switching to WKWebView and see how things pan out from there.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
NSURLConnection Error Code -1100
 
 
Q