Skip to content

Instantly share code, notes, and snippets.

@mlcollard
Last active May 4, 2018 02:59
Show Gist options
  • Save mlcollard/86591f71024d2da9f65a to your computer and use it in GitHub Desktop.
Save mlcollard/86591f71024d2da9f65a to your computer and use it in GitHub Desktop.
iOS: Loading a WKWebView with a web URL
/* Load given URL into web view */
/* Note: For http:, need to setup App Transport Settings to allow:
Key: App Transport Security Settings
Subkey: Allow Arbitrary Loads to YES
Produces:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
This allows any URL, but is NOT good practice.
Should only allow specific URLS (Exception Domains
*/
guard let url = URL(string: "http://mlcollard.net/cs489iOSS18/") else {
print("Error: Unable to load url")
return
}
let requestObj = URLRequest(url: url)
self.classWebView?.load(requestObj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment