title: An SSL error has occurred, but data is received
body: <p>I tried many options including those provided on stackoverflow and nothing helps. If i don't enter in my application during one hour or more i receive ssl error and my method doesn't execute.</p>
  
  <pre><code>        test.getModelFromQuarter { (result) in
          if result {
              print("*********SUCCESS********")
  
              DispatchQueue.main.async {
                  self.setChart(dataPoints: self.test.getDataPoint(for: .week), values: self.test.getDefaultCCY(from: .week)!.values)
  
                  self.activityIndicator.stopAnimating()
  
                  self.currencyBanner.text = "НБУ - \(self.test.getDefaultCCY(from: .week)!.values.last!) \(self.test.getDefaultCCY(from: .week)!.ccy)"
  
                  self.setComparingImage(firstValue: (self.test.getDefaultCCY(from: .week)?.values.last)!, secondValue: (self.test.getDefaultCCY(from: .week)?.values.dropLast().last)!)
              }
          }
  </code></pre>
  
  <p>This is the method with issue. </p>
  
  <pre><code>    func load(url: String, handler: @escaping ([CCYModel]) -&gt; Void) {
      var ccyModels: [CCYModel] = []
  
      Alamofire.request(url).responseJSON { (response) in
          if response.result.isSuccess {
              if let json = try? JSON(response.result.value!) {
  
                  if let array = json.array {
                      for json in array {
                          let model = CCYModel(ccy: json["cc"].stringValue, rate: json["rate"].doubleValue)
                          ccyModels.append(model)
                      }
                  }
              }
          } else {
              print("*************************")
              print("Fetching currencies error \(response.result.error)")
              print("*************************")
          }
  
          handler(ccyModels)
      }
  }
  </code></pre>
  
  <p>This can be fixed by restarting application or by "reloading ui" which means that <strong>the data from the site is successfully loaded</strong>. </p>
  
  <p>This is my plist where i tried to fix the problem.</p>
  
  <pre><code>    &lt;key&gt;NSAppTransportSecurity&lt;/key&gt;
  &lt;dict&gt;
      &lt;key&gt;NSAllowsArbitraryLoads&lt;/key&gt;
      &lt;true/&gt;
      &lt;key&gt;NSAllowsArbitraryLoadsForMedia&lt;/key&gt;
      &lt;true/&gt;
      &lt;key&gt;NSAllowsArbitraryLoadsInWebContent&lt;/key&gt;
      &lt;true/&gt;
      &lt;key&gt;NSAllowsArbitraryLoadsUsageDescription&lt;/key&gt;
      &lt;dict/&gt;
      &lt;key&gt;NSExceptionDomains&lt;/key&gt;
      &lt;dict&gt;
          &lt;key&gt;NSIncludesSubdomains&lt;/key&gt;
          &lt;true/&gt;
          &lt;key&gt;NSTemporaryExceptionAllowsInsecureHTTPLoads&lt;/key&gt;
          &lt;true/&gt;
          &lt;key&gt;NSTemporaryExceptionMinimumTLSVersion&lt;/key&gt;
          &lt;string&gt;TLSv1.2&lt;/string&gt;
          &lt;key&gt;https://bank.gov.ua/&lt;/key&gt;
          &lt;dict/&gt;
      &lt;/dict&gt;
      &lt;key&gt;NSTemporaryExceptionRequiresForwardSecrecy&lt;/key&gt;
      &lt;false/&gt;
  &lt;/dict&gt;
  </code></pre>
  
  <p>It shows the xcode console when bug occurs: </p>
  
  <pre><code>&gt; 2020-01-29 18:07:59.434236+0200 CurrencyInfo[28221:10222320] []
  &gt; nw_socket_handle_socket_event [C2.1:3] Socket SO_ERROR [54: Connection
  &gt; reset by peer] 2020-01-29 18:07:59.444060+0200
  &gt; CurrencyInfo[28221:10222320] Connection 2: received failure
  &gt; notification 2020-01-29 18:07:59.444610+0200
  &gt; CurrencyInfo[28221:10222320] Connection 2: failed to connect 3:-9816,
  &gt; reason -1 2020-01-29 18:07:59.444619+0200 CurrencyInfo[28221:10222320]
  &gt; Connection 2: encountered error(3:-9816) 2020-01-29
  &gt; 18:07:59.445001+0200 CurrencyInfo[28221:10222320] Task
  &gt; &lt;89311F11-5FE1-4BD4-9792-82C796CBE14F&gt;.&lt;2&gt; HTTP load failed, 0/0 bytes
  &gt; (error code: -1200 [3:-9816]) 2020-01-29 18:07:59.456604+0200
  &gt; CurrencyInfo[28221:10222320] Task
  &gt; &lt;89311F11-5FE1-4BD4-9792-82C796CBE14F&gt;.&lt;2&gt; finished with error [-1200]
  &gt; Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred
  &gt; and a secure connection to the server cannot be made."
  &gt; UserInfo={NSErrorFailingURLStringKey=https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange?date=20200129&amp;json,
  &gt; NSLocalizedRecoverySuggestion=Would you like to connect to the server
  &gt; anyway?, _kCFStreamErrorDomainKey=3,
  &gt; _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask &lt;89311F11-5FE1-4BD4-9792-82C796CBE14F&gt;.&lt;2&gt;,
  &gt; _NSURLErrorRelatedURLSessionTaskErrorKey=(
  &gt;     "LocalDataTask &lt;89311F11-5FE1-4BD4-9792-82C796CBE14F&gt;.&lt;2&gt;" ), NSLocalizedDescription=An SSL error has occurred and a secure
  &gt; connection to the server cannot be made.,
  &gt; NSErrorFailingURLKey=https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange?date=20200129&amp;json,
  &gt; NSUnderlyingError=0x2801a03c0 {Error Domain=kCFErrorDomainCFNetwork
  &gt; Code=-1200 "(null)"
  &gt; UserInfo={_kCFStreamPropertySSLClientCertificateState=0,
  &gt; _kCFNetworkCFStreamSSLErrorOriginalValue=-9816, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9816}}, _kCFStreamErrorCodeKey=-9816}
  &gt; ************************* Fetching currencies error Optional(Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a
  &gt; secure connection to the server cannot be made."
  &gt; UserInfo={NSErrorFailingURLStringKey=https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange?date=20200129&amp;json,
  &gt; NSLocalizedRecoverySuggestion=Would you like to connect to the server
  &gt; anyway?, _kCFStreamErrorDomainKey=3,
  &gt; _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask &lt;89311F11-5FE1-4BD4-9792-82C796CBE14F&gt;.&lt;2&gt;,
  &gt; _NSURLErrorRelatedURLSessionTaskErrorKey=(
  &gt;     "LocalDataTask &lt;89311F11-5FE1-4BD4-9792-82C796CBE14F&gt;.&lt;2&gt;" ), NSLocalizedDescription=An SSL error has occurred and a secure
  &gt; connection to the server cannot be made.,
  &gt; NSErrorFailingURLKey=https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange?date=20200129&amp;json,
  &gt; NSUnderlyingError=0x2801a03c0 {Error Domain=kCFErrorDomainCFNetwork
  &gt; Code=-1200 "(null)"
  &gt; UserInfo={_kCFStreamPropertySSLClientCertificateState=0,
  &gt; _kCFNetworkCFStreamSSLErrorOriginalValue=-9816, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9816}}, _kCFStreamErrorCodeKey=-9816})
  &gt; *************************
  </code></pre>
  
  <p>I also checked with <code>nscurl --ats-diagnostics --verbose</code></p>
  
  <pre><code>&gt;  ~ % nscurl --ats-diagnostics --verbose https://bank.gov.ua Starting
  &gt; ATS Diagnostics
  &gt; 
  &gt; Configuring ATS Info.plist keys and displaying the result of HTTPS
  &gt; loads to https://bank.gov.ua. A test will "PASS" if
  &gt; URLSession:task:didCompleteWithError: returns a nil error.
  &gt; ================================================================================
  &gt; 
  &gt; Default ATS Secure Connection
  &gt; --- ATS Default Connection ATS Dictionary: { } Result : PASS
  &gt; ---
  &gt; 
  &gt; ================================================================================
  &gt; 
  &gt; Allowing Arbitrary Loads
  &gt; 
  &gt; --- Allow All Loads ATS Dictionary: {
  &gt;     NSAllowsArbitraryLoads = true; } Result : PASS
  &gt; ---
  &gt; 
  &gt; ================================================================================
  &gt; 
  &gt; Configuring TLS exceptions for bank.gov.ua
  &gt; 
  &gt; --- TLSv1.3 ATS Dictionary: {
  &gt;     NSExceptionDomains =     {
  &gt;         "bank.gov.ua" =         {
  &gt;             NSExceptionMinimumTLSVersion = "TLSv1.3";
  &gt;         };
  &gt;     }; } Result : FAIL Error : Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the
  &gt; server cannot be made."
  &gt; UserInfo={NSErrorFailingURLStringKey=https://bank.gov.ua/,
  &gt; NSLocalizedRecoverySuggestion=Would you like to connect to the server
  &gt; anyway?, _kCFStreamErrorDomainKey=3,
  &gt; _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask &lt;1BDB6BF8-A49A-44D9-93B9-A28E86DF7CA9&gt;.&lt;1&gt;,
  &gt; _NSURLErrorRelatedURLSessionTaskErrorKey=(
  &gt;     "LocalDataTask &lt;1BDB6BF8-A49A-44D9-93B9-A28E86DF7CA9&gt;.&lt;1&gt;" ), NSLocalizedDescription=An SSL error has occurred and a secure
  &gt; connection to the server cannot be made.,
  &gt; NSErrorFailingURLKey=https://bank.gov.ua/,
  &gt; NSUnderlyingError=0x7f8878428810 {Error Domain=kCFErrorDomainCFNetwork
  &gt; Code=-1200 "(null)"
  &gt; UserInfo={_kCFStreamPropertySSLClientCertificateState=0,
  &gt; _kCFNetworkCFStreamSSLErrorOriginalValue=-9858, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9858}}, _kCFStreamErrorCodeKey=-9858}
  &gt; ---
  &gt; 
  &gt; --- TLSv1.2 ATS Dictionary: {
  &gt;     NSExceptionDomains =     {
  &gt;         "bank.gov.ua" =         {
  &gt;             NSExceptionMinimumTLSVersion = "TLSv1.2";
  &gt;         };
  &gt;     }; } Result : PASS
  &gt; ---
  &gt; 
  &gt; --- TLSv1.1 ATS Dictionary: {
  &gt;     NSExceptionDomains =     {
  &gt;         "bank.gov.ua" =         {
  &gt;             NSExceptionMinimumTLSVersion = "TLSv1.1";
  &gt;         };
  &gt;     }; } Result : PASS
  &gt; ---
  &gt; 
  &gt; --- TLSv1.0 ATS Dictionary: {
  &gt;     NSExceptionDomains =     {
  &gt;         "bank.gov.ua" =         {
  &gt;             NSExceptionMinimumTLSVersion = "TLSv1.0";
  &gt;         };
  &gt;     }; } Result : PASS
  &gt; ---
  &gt; 
  &gt; ================================================================================
  &gt; 
  &gt; Configuring PFS exceptions for bank.gov.ua
  &gt; 
  &gt; --- Disabling Perfect Forward Secrecy ATS Dictionary: {
  &gt;     NSExceptionDomains =     {
  &gt;         "bank.gov.ua" =         {
  &gt;             NSExceptionRequiresForwardSecrecy = false;
  &gt;         };
  &gt;     }; } Result : PASS
  &gt; ---
  &gt; 
  &gt; ================================================================================
  &gt; 
  &gt; Configuring PFS exceptions and allowing insecure HTTP for bank.gov.ua
  &gt; 
  &gt; --- Disabling Perfect Forward Secrecy and Allowing Insecure HTTP ATS Dictionary: {
  &gt;     NSExceptionDomains =     {
  &gt;         "bank.gov.ua" =         {
  &gt;             NSExceptionAllowsInsecureHTTPLoads = true;
  &gt;             NSExceptionRequiresForwardSecrecy = false;
  &gt;         };
  &gt;     }; } Result : PASS
  &gt; ---
  &gt; 
  &gt; ================================================================================
  &gt; 
  &gt; Configuring TLS exceptions with PFS disabled for bank.gov.ua
  &gt; 
  &gt; --- TLSv1.3 with PFS disabled ATS Dictionary: {
  &gt;     NSExceptionDomains =     {
  &gt;         "bank.gov.ua" =         {
  &gt;             NSExceptionMinimumTLSVersion = "TLSv1.3";
  &gt;             NSExceptionRequiresForwardSecrecy = false;
  &gt;         };
  &gt;     }; } Result : FAIL Error : Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the
  &gt; server cannot be made."
  &gt; UserInfo={NSErrorFailingURLStringKey=https://bank.gov.ua/,
  &gt; NSLocalizedRecoverySuggestion=Would you like to connect to the server
  &gt; anyway?, _kCFStreamErrorDomainKey=3,
  &gt; _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask &lt;AA01562F-24EA-4DC9-BCF7-6E9D625D9361&gt;.&lt;1&gt;,
  &gt; _NSURLErrorRelatedURLSessionTaskErrorKey=(
  &gt;     "LocalDataTask &lt;AA01562F-24EA-4DC9-BCF7-6E9D625D9361&gt;.&lt;1&gt;" ), NSLocalizedDescription=An SSL error has occurred and a secure
  &gt; connection to the server cannot be made.,
  &gt; NSErrorFailingURLKey=https://bank.gov.ua/,
  &gt; NSUnderlyingError=0x7f887a800470 {Error Domain=kCFErrorDomainCFNetwork
  &gt; Code=-1200 "(null)"
  &gt; UserInfo={_kCFStreamPropertySSLClientCertificateState=0,
  &gt; _kCFNetworkCFStreamSSLErrorOriginalValue=-9858, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9858}}, _kCFStreamErrorCodeKey=-9858}
  &gt; ---
  &gt; 
  &gt; --- TLSv1.2 with PFS disabled ATS Dictionary: {
  &gt;     NSExceptionDomains =     {
  &gt;         "bank.gov.ua" =         {
  &gt;             NSExceptionMinimumTLSVersion = "TLSv1.2";
  &gt;             NSExceptionRequiresForwardSecrecy = false;
  &gt;         };
  &gt;     }; } Result : PASS
  &gt; ---
  &gt; 
  &gt; --- TLSv1.1 with PFS disabled ATS Dictionary: {
  &gt;     NSExceptionDomains =     {
  &gt;         "bank.gov.ua" =         {
  &gt;             NSExceptionMinimumTLSVersion = "TLSv1.1";
  &gt;             NSExceptionRequiresForwardSecrecy = false;
  &gt;         };
  &gt;     }; } Result : PASS
  &gt; ---
  &gt; 
  &gt; --- TLSv1.0 with PFS disabled ATS Dictionary: {
  &gt;     NSExceptionDomains =     {
  &gt;         "bank.gov.ua" =         {
  &gt;             NSExceptionMinimumTLSVersion = "TLSv1.0";
  &gt;             NSExceptionRequiresForwardSecrecy = false;
  &gt;         };
  &gt;     }; } Result : PASS
  &gt; ---
  &gt; 
  &gt; ================================================================================
  &gt; 
  &gt; Configuring TLS exceptions with PFS disabled and insecure HTTP allowed
  &gt; for bank.gov.ua
  &gt; 
  &gt; --- TLSv1.3 with PFS disabled and insecure HTTP allowed ATS Dictionary: {
  &gt;     NSExceptionDomains =     {
  &gt;         "bank.gov.ua" =         {
  &gt;             NSExceptionAllowsInsecureHTTPLoads = true;
  &gt;             NSExceptionMinimumTLSVersion = "TLSv1.3";
  &gt;             NSExceptionRequiresForwardSecrecy = false;
  &gt;         };
  &gt;     }; } Result : FAIL Error : Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the
  &gt; server cannot be made."
  &gt; UserInfo={NSErrorFailingURLStringKey=https://bank.gov.ua/,
  &gt; NSLocalizedRecoverySuggestion=Would you like to connect to the server
  &gt; anyway?, _kCFStreamErrorDomainKey=3,
  &gt; _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask &lt;BDF920C9-E44E-4DCD-BED7-94274E454AF4&gt;.&lt;1&gt;,
  &gt; _NSURLErrorRelatedURLSessionTaskErrorKey=(
  &gt;     "LocalDataTask &lt;BDF920C9-E44E-4DCD-BED7-94274E454AF4&gt;.&lt;1&gt;" ), NSLocalizedDescription=An SSL error has occurred and a secure
  &gt; connection to the server cannot be made.,
  &gt; NSErrorFailingURLKey=https://bank.gov.ua/,
  &gt; NSUnderlyingError=0x7f887a800390 {Error Domain=kCFErrorDomainCFNetwork
  &gt; Code=-1200 "(null)"
  &gt; UserInfo={_kCFStreamPropertySSLClientCertificateState=0,
  &gt; _kCFNetworkCFStreamSSLErrorOriginalValue=-9858, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9858}}, _kCFStreamErrorCodeKey=-9858}
  &gt; ---
  &gt; 
  &gt; --- TLSv1.2 with PFS disabled and insecure HTTP allowed ATS Dictionary: {
  &gt;     NSExceptionDomains =     {
  &gt;         "bank.gov.ua" =         {
  &gt;             NSExceptionAllowsInsecureHTTPLoads = true;
  &gt;             NSExceptionMinimumTLSVersion = "TLSv1.2";
  &gt;             NSExceptionRequiresForwardSecrecy = false;
  &gt;         };
  &gt;     }; } Result : PASS
  &gt; ---
  &gt; 
  &gt; --- TLSv1.1 with PFS disabled and insecure HTTP allowed ATS Dictionary: {
  &gt;     NSExceptionDomains =     {
  &gt;         "bank.gov.ua" =         {
  &gt;             NSExceptionAllowsInsecureHTTPLoads = true;
  &gt;             NSExceptionMinimumTLSVersion = "TLSv1.1";
  &gt;             NSExceptionRequiresForwardSecrecy = false;
  &gt;         };
  &gt;     }; } Result : PASS
  &gt; ---
  &gt; 
  &gt; --- TLSv1.0 with PFS disabled and insecure HTTP allowed ATS Dictionary: {
  &gt;     NSExceptionDomains =     {
  &gt;         "bank.gov.ua" =         {
  &gt;             NSExceptionAllowsInsecureHTTPLoads = true;
  &gt;             NSExceptionMinimumTLSVersion = "TLSv1.0";
  &gt;             NSExceptionRequiresForwardSecrecy = false;
  &gt;         };
  &gt;     }; } Result : PASS
  &gt; ---
  &gt; 
  &gt; ============================================================================
  </code></pre>
  
  <p>Is it possible for xcode to ignoring this error? Because my app working fine, data is loaded. Just method in viewDidLoad sometimes doesn't load ui. </p>