Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WKWebView is not loading url

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.

like image 827
user3245722 Avatar asked Dec 02 '17 06:12

user3245722


Video Answer


2 Answers

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

like image 141
iPatel Avatar answered Sep 21 '22 13:09

iPatel


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/>
like image 25
Mick Avatar answered Sep 23 '22 13:09

Mick