Experts, I'm a Beginner in IOS 9 / XCODE 7 / Swift 2 Development Kit
I'm trying to create an ios app that simply route to Web Application in HTTPS protocol. Below is my code so far in ViewController.swift
import UIKit
class ViewController: UIViewController {
@IBOutlet var myWebView: UIWebView!
/**
* Function to Display the Web Application initial URL
*/
func loadAppURL(){
let siteAddress = "https://domain:8443/path/to/page"
let url = NSURL (string: siteAddress)
let urlRequest = NSURLRequest(URL: url!)
myWebView.loadRequest(urlRequest)
}
override func viewDidLoad() {
super.viewDidLoad()
loadAppURL()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
While Building my App it shows the below Error Message
2015-10-01 01:05:13.879 Web Page Tester[2947:31838] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9807)
and if i try building my app instead of "https://domain:8443/path/to/page" with "http://www.apple.com" its works fine.
I can access my web application in Safari and it asks for accepting the security risks. and i accept it and i can access my Application.
Guide me to fix my issues, Thanks in advance.
In Swift 3.
Step 1. Add
NSURLConnectionDelegate
to your viewcontroller, to overwrite methods.Step 2. Override viewDidLoad
Step 3 Overwrite
canAuthenticateAgainstProtectionSpace
anddidReceive challenge
Thanks Navas Basheer for the original solution! Saved me a ton of time
edit Info.plist, Add:
it's work for me, XCode 7.3
1- Create category "NSURLRequestCategory" -> after import this category to your bridge file created by xcode (don't forget to let xCode create one if you dont haven't) and put this code :
Create your load request UIWebView normally :
Enjoyyy :D
Finally I fixed it
Xcode will reject un-trusted self signed certificates from servers by default.
we can override this Using
NSURLConnection
and can communicate with a self-signed server, since we have the ability to control the authentication through the additional delegate methods which are not available to a UIWebView. So usingconnection:didReceiveAuthenticationChallenge
we can authenticate against the self signed server.References NSURLAuthenticationChallenge Docs , @Lilo Lu's Question
I Resolved My Issue in below steps
Step 1 : Defined a
NSURLConnection
inviewDidLoad()
method of my viewController.swift as followsStep 2 : used NSURLConnection delegate methods
and that worked !!
You can add the following to your plist