Connect to a Server with Invalid Certificate using NSURLSession (swift2,xcode7,ios9)

前端 未结 5 717
栀梦
栀梦 2021-01-13 05:55

I\'m using Xcode 7, Swift 2, and iOS9. I want to connect to a web service using NSURLSession but I get the following error when I try to connect:

2015-10-13          


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-13 06:40

    For SWIFT 4:

    func URLSession(session: URLSession, didReceiveChallenge challenge: URLAuthenticationChallenge, completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
        completionHandler(
            .useCredential,
            URLCredential(trust: challenge.protectionSpace.serverTrust!)
        )
    }
    

提交回复
热议问题