I am loading a webview with a url, which is maintaining the user session. now this url, once it verifies that the session details are correct, returns a iframe in the html body.
I have to load this iframe in my webview. The html body would be like the following:
<body style="margin:0; padding:0">
<iframe style="height:100vh;width:100%;border:0" src="https:....
Any help would be appreciated.
Finally i did manage to get it :)
var urlRequest = URLRequest.init(url: URL.init(string: urlString)!)
urlRequest.httpMethod = "GET"
let token:String! = "Bearer \((token)!)"
urlRequest.addValue(token!, forHTTPHeaderField: "Authorization")
urlRequest.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
urlRequest.httpShouldHandleCookies = true
let session = URLSession.shared
if delegate != nil {
delegate?.showActivityIndicator()
}
let task = session.dataTask(with: urlRequest, completionHandler: { (data, response, error) in
if error != nil {
return
}
let body = String(data: data!, encoding: .utf8)
self.webView.loadHTMLString(body!, baseURL: nil)
})
task.resume()