Ios 如何在Swift Alamofire中使用ssl证书?

Ios 如何在Swift Alamofire中使用ssl证书?,ios,swift,ssl,https,alamofire,Ios,Swift,Ssl,Https,Alamofire,我正在用HTTPS web服务升级我的iOS应用程序 我已经用SSL证书升级了我的web服务器。但不知道从iOS代码方面该怎么做 我需要在web请求中传递任何证书吗 我正在使用Alamofire进行web请求 谢谢简单的谷歌搜索会给你带来很多结果 比如说, 您当前的代码有问题吗?如果是,它们是什么?询问您的提供商因为我以前从未使用过自定义证书,如何验证是否正确添加?如果我向另一个域发出请求,它会失败吗? func configureAlamoFireSSLPinning { let p

我正在用HTTPS web服务升级我的iOS应用程序

我已经用SSL证书升级了我的web服务器。但不知道从iOS代码方面该怎么做

我需要在web请求中传递任何证书吗

我正在使用Alamofire进行web请求


谢谢

简单的谷歌搜索会给你带来很多结果

比如说,


您当前的代码有问题吗?如果是,它们是什么?询问您的提供商因为我以前从未使用过自定义证书,如何验证是否正确添加?如果我向另一个域发出请求,它会失败吗?
func configureAlamoFireSSLPinning {
     let pathToCert = NSBundle.mainBundle().pathForResource(githubCert, ofType: "cer")
     let localCertificate:NSData = NSData(contentsOfFile: pathToCert!)!

     self.serverTrustPolicy = ServerTrustPolicy.PinCertificates(
            certificates: [SecCertificateCreateWithData(nil, localCertificate)!],
         validateCertificateChain: true,
         validateHost: true
     )

     self.serverTrustPolicies = [
         "your-api.com": self.serverTrustPolicy!
     ]

     self.afManager = Manager(
         configuration: NSURLSessionConfiguration.defaultSessionConfiguration(),
         serverTrustPolicyManager: ServerTrustPolicyManager(policies: self.serverTrustPolicies)
     )
 }

func alamoFireRequestHandler {
     self.afManager.request(.GET, self.urlTextField.text!)
         .response { request, response, data, error in
      // response management code
  }
}