16

WKWebview is not loading certain urls. this is my code snippet

let myURL = URL(string: "https://contents.tdscpc.gov.in/")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)

when I change the url to say URL(string: "https://www.ndtv.com/") it works . Not sure why? any suggestions will be really helpful.

Mick
  • 30,759
  • 16
  • 111
  • 130
user3245722
  • 323
  • 2
  • 3
  • 9

2 Answers2

30

First check did you set the permission in the info.plist file ? If not then you just need to take permission of TransportSecurit to YES in info.plist file

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

Like below

enter image description here

iPatel
  • 46,010
  • 16
  • 115
  • 137
11

Mac App Devs

If you are building an app for the Mac, make sure to turn App Sandbox ON in your target and tick Networks Incoming/Outgoing Connections.

enter image description here


Update: If you prefer the long way, add the following to YourAppName.entitlements

<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
Mick
  • 30,759
  • 16
  • 111
  • 130
  • Updated @Moritz - downvoting is a bit harsh :) Hope that makes you happier with the update! – Mick Dec 09 '18 at 11:27