1. write code like this
/*
let url = URL(string: "https://www.stackoverflow.com")!
webview.loadRequest(URLRequest(url: url))
webview.loadHTMLString("<h1>Hello there!</h1>", baseURL: nil)
*/
if let url = URL(string: "https://www.stackoverflow.com") {
let request = NSMutableURLRequest(url: url)
let task = URLSession.shared.dataTask(with: request as URLRequest) {
data, response, error in
if error != nil {
print(error!)
} else {
if let unwrappedData = data {
let dataString = NSString(data: unwrappedData, encoding: String.Encoding.utf8.rawValue)
print(dataString!)
DispatchQueue.main.sync(execute: {
// Update UI
})
}
}
}
task.resume()
}
2. modify Info.list file
//App Transport Security Settings
//Allow Arbitrary Loads
//Exception Domains
//NSTemporaryExceptionAllowsInsecureHTTPLoads
//NSIncludesSubdomains