I have tried many solutions like this below to allow my application to connect using Swift 3 and ignoring Self Signed Certificate with no success.
https://stackoverflow.com/a/30820452/7126704
My Login function that connect:
func Login(_ user: String, psw: String){
loading = MBProgressHUD.showAdded(to: self.view, animated: true)
loading.isUserInteractionEnabled = false
self.view.isUserInteractionEnabled = false
Accedi.isEnabled = false
let userPost = "&username=" + user
let passPost = "&password=" + md5(string: psw)
let postString = "func=LOGIN" + userPost + passPost + "&appver=" + getAppVersion()
let request = NSMutableURLRequest(url: URL(string: ServerPath)!)
request.httpMethod = "POST"
request.httpBody = postString.data(using: String.Encoding.utf8)
request.timeoutInterval = 10
let configuration = URLSessionConfiguration.default
let session = URLSession(configuration: configuration, delegate: self, delegateQueue: OperationQueue.main)
let task = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) in
guard error == nil && data != nil else {
let getError:NSString = (error?.localizedDescription)! as NSString
print("[Login] Error = \(getError)")
if ((self.usernameField.text! != "") || (self.passwordField.text! != "")){
self.Accedi.isEnabled = true
}else{
self.Accedi.isEnabled = false
}
DispatchQueue.main.async {
loading.hide(animated: true)
self.view.isUserInteractionEnabled = true
let alert = UIAlertController(title: sError, message: sConnError + ": \(getError)", preferredStyle: UIAlertControllerStyle.alert)
alert.view.tintColor = globalColor
alert.addAction(UIAlertAction(title: sOk, style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
return
} [...]
What solution i can use to solve this problem? A little example can help me and others a lot.