2

I'm calling an endpoint that has a self-signed ssl certificate i have tried adding this in my info.plist

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

But i am still not able to access the endpoint i keep getting this

NSLocalizedDescription=The certificate for this server is invalid. You might be connecting to a server that is pretending to be “endpoint” which could put your confidential information at risk.
Sagaya Abdul
  • 151
  • 1
  • 11
  • Possible duplicate of https://stackoverflow.com/questions/19507207/how-do-i-accept-a-self-signed-ssl-certificate-using-ios-7s-nsurlsession-and-its?rq=1. – Martin R Mar 26 '18 at 17:03
  • I am using Alamofire if you can provide a workaround it with Alamofire...thank you – Sagaya Abdul Mar 26 '18 at 17:14

1 Answers1

3

You need to create a session manager and tell it to disable evaluation of the ssl in that server.

Something like this

static var manager: Alamofire.SessionManager = {
    let serverTrustPolicies: [String: ServerTrustPolicy] = [
        "https://example.com": .disableEvaluation
    ]

    let configuration = URLSessionConfiguration.default
    configuration.httpAdditionalHeaders = Alamofire.SessionManager.defaultHTTPHeaders
    let manager = Alamofire.SessionManager(
        configuration: URLSessionConfiguration.default,
        serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies)
    )

    return manager
}()

An then, instead of calling request in Alamofire, like this

Alamofire.request("https://example.com", method: .get…

you call it in your manager

manager.request("https://example.com"…
Gonzo
  • 1,533
  • 16
  • 28