I have a problem with loading UIWebView
, using https
request.
I have read some related answers, but they have confused me even more.
Here is my code:
The link, I'm using below will redirect to another page.
class PartnersWebViewControlerViewController: UIViewController, NSURLConnectionDelegate, UIWebViewDelegate {
@IBOutlet weak var admitadWebView: UIWebView!
let url = "https://ad.admitad.com/g/54tjzvqfv92260a476c4ffa09d8e84/subid/26/"
override func viewDidLoad() {
super.viewDidLoad()
admitadWebView.delegate = self
let requestURL = URL(string:url)
let request = URLRequest(url: requestURL!)
admitadWebView.loadRequest(request)
}
}
However everything is loading fine, when I change https
to http
With the help of this answer
UIWebView to view self signed websites (No private api, not NSURLConnection) - is it possible?
I tried to conform those protocols NSURLConnectionDelegate
, UIWebViewDelegate
in a following way
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
let urlConnection: NSURLConnection = NSURLConnection(request: request as URLRequest, delegate: self)!
urlConnection.start()
return true
}
func connection(_ connection: NSURLConnection, canAuthenticateAgainstProtectionSpace protectionSpace: URLProtectionSpace) -> Bool {
return true
}
func connection(_ connection: NSURLConnection, didReceive challenge: URLAuthenticationChallenge) {
let host = "www.ad.admitad.com"
if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust &&
challenge.protectionSpace.host == host {
let credential = URLCredential(trust: challenge.protectionSpace.serverTrust!)
challenge.sender!.use(credential, for: challenge)
} else {
challenge.sender!.performDefaultHandling!(for: challenge)
}
}
But still, I have white screen and nothing prints to log.
Any help is appreciate. It the first time I stuck with such problem, so sorry if my questions seems dummy.
I'm using ios 10.3 UPD: this problem occurs only when launching on device (iphone 6)