LoginSignup
1
1

More than 3 years have passed since last update.

Alamofire4でSSLエラーを無視し、自己証明書のサーバにリクエストする

Last updated at Posted at 2017-06-30

Alamofire4のサンプルが見つからなかったので紹介させて頂きます。
このようなクラスを用意して対応しました。

import Alamofire

struct WebAPI {
    static let sessionManager: SessionManager = {
        switch MyEnvironment.server {
        case .development:
            return Alamofire.SessionManager(
                serverTrustPolicyManager: ServerTrustPolicyManagerForDevelop()
            )
        case .staging, .production:
            return Alamofire.SessionManager()
        }
    }()

    private class ServerTrustPolicyManagerForDevelop: ServerTrustPolicyManager {

        init() {
            super.init(policies: [:])
        }

        override func serverTrustPolicy(forHost host: String) -> ServerTrustPolicy? {
            return .disableEvaluation
        }
    }

}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1