Search code examples
iosuiwebview

Swift UIWebView not loading http sites


I created a web view controller and it loads https sites(ex: , ) but not http, non ssl secured sites(ex: http://bswd.us, http://www.barretthillins.com). When i do put a hhtp site in there, it does load but just a blank, white web view. How would i need to fix this?


Solution

  • This is due to the App Transport Security, a new protocol introduced by Apple at WWDC 2015. It doesn't allow any connections that are not HTTPS. You can disable it, however it's not recommended as it secures your app.

    To disable it you have to edit the App's .plist. Simply right-click the .plist file and select Open As -> Source File and add the following code:

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key><true/>
    </dict>
    

    This will allow HTTP requests.

    Hope that helps, Julian.