Я перепробовал много опций, в том числе и те, которые представлены в stackoverflow, и ничего не помогло. Если я не вхожу в свое приложение в течение одного часа или более, я получаю сообщение об ошибке ssl, и мой метод не выполняется.
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)!)
}
}
Это метод с проблемой.
func load(url: String, handler: @escaping ([CCYModel]) -> 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)
}
}
Это можно исправить путем перезапуска приложения или «перезагрузки пользовательского интерфейса», что означает, что данные с сайта успешно загружены .
Это мой список, где я пытался решить проблему.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsArbitraryLoadsForMedia</key>
<true/>
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>
<key>NSAllowsArbitraryLoadsUsageDescription</key>
<dict/>
<key>NSExceptionDomains</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.2</string>
<key>https://bank.gov.ua/</key>
<dict/>
</dict>
<key>NSTemporaryExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
Показывает консоль xcode при возникновении ошибки:
> 2020-01-29 18:07:59.434236+0200 CurrencyInfo[28221:10222320] []
> nw_socket_handle_socket_event [C2.1:3] Socket SO_ERROR [54: Connection
> reset by peer] 2020-01-29 18:07:59.444060+0200
> CurrencyInfo[28221:10222320] Connection 2: received failure
> notification 2020-01-29 18:07:59.444610+0200
> CurrencyInfo[28221:10222320] Connection 2: failed to connect 3:-9816,
> reason -1 2020-01-29 18:07:59.444619+0200 CurrencyInfo[28221:10222320]
> Connection 2: encountered error(3:-9816) 2020-01-29
> 18:07:59.445001+0200 CurrencyInfo[28221:10222320] Task
> <89311F11-5FE1-4BD4-9792-82C796CBE14F>.<2> HTTP load failed, 0/0 bytes
> (error code: -1200 [3:-9816]) 2020-01-29 18:07:59.456604+0200
> CurrencyInfo[28221:10222320] Task
> <89311F11-5FE1-4BD4-9792-82C796CBE14F>.<2> finished with error [-1200]
> Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred
> and a secure connection to the server cannot be made."
> UserInfo={NSErrorFailingURLStringKey=https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange?date=20200129&json,
> NSLocalizedRecoverySuggestion=Would you like to connect to the server
> anyway?, _kCFStreamErrorDomainKey=3,
> _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <89311F11-5FE1-4BD4-9792-82C796CBE14F>.<2>,
> _NSURLErrorRelatedURLSessionTaskErrorKey=(
> "LocalDataTask <89311F11-5FE1-4BD4-9792-82C796CBE14F>.<2>" ), NSLocalizedDescription=An SSL error has occurred and a secure
> connection to the server cannot be made.,
> NSErrorFailingURLKey=https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange?date=20200129&json,
> NSUnderlyingError=0x2801a03c0 {Error Domain=kCFErrorDomainCFNetwork
> Code=-1200 "(null)"
> UserInfo={_kCFStreamPropertySSLClientCertificateState=0,
> _kCFNetworkCFStreamSSLErrorOriginalValue=-9816, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9816}}, _kCFStreamErrorCodeKey=-9816}
> ************************* Fetching currencies error Optional(Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a
> secure connection to the server cannot be made."
> UserInfo={NSErrorFailingURLStringKey=https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange?date=20200129&json,
> NSLocalizedRecoverySuggestion=Would you like to connect to the server
> anyway?, _kCFStreamErrorDomainKey=3,
> _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <89311F11-5FE1-4BD4-9792-82C796CBE14F>.<2>,
> _NSURLErrorRelatedURLSessionTaskErrorKey=(
> "LocalDataTask <89311F11-5FE1-4BD4-9792-82C796CBE14F>.<2>" ), NSLocalizedDescription=An SSL error has occurred and a secure
> connection to the server cannot be made.,
> NSErrorFailingURLKey=https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange?date=20200129&json,
> NSUnderlyingError=0x2801a03c0 {Error Domain=kCFErrorDomainCFNetwork
> Code=-1200 "(null)"
> UserInfo={_kCFStreamPropertySSLClientCertificateState=0,
> _kCFNetworkCFStreamSSLErrorOriginalValue=-9816, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9816}}, _kCFStreamErrorCodeKey=-9816})
> *************************
Я также проверил с помощью nscurl --ats-diagnostics --verbose
> ~ % nscurl --ats-diagnostics --verbose https://bank.gov.ua Starting
> ATS Diagnostics
>
> Configuring ATS Info.plist keys and displaying the result of HTTPS
> loads to https://bank.gov.ua. A test will "PASS" if
> URLSession:task:didCompleteWithError: returns a nil error.
> ================================================================================
>
> Default ATS Secure Connection
> --- ATS Default Connection ATS Dictionary: { } Result : PASS
> ---
>
> ================================================================================
>
> Allowing Arbitrary Loads
>
> --- Allow All Loads ATS Dictionary: {
> NSAllowsArbitraryLoads = true; } Result : PASS
> ---
>
> ================================================================================
>
> Configuring TLS exceptions for bank.gov.ua
>
> --- TLSv1.3 ATS Dictionary: {
> NSExceptionDomains = {
> "bank.gov.ua" = {
> NSExceptionMinimumTLSVersion = "TLSv1.3";
> };
> }; } Result : FAIL Error : Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the
> server cannot be made."
> UserInfo={NSErrorFailingURLStringKey=https://bank.gov.ua/,
> NSLocalizedRecoverySuggestion=Would you like to connect to the server
> anyway?, _kCFStreamErrorDomainKey=3,
> _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <1BDB6BF8-A49A-44D9-93B9-A28E86DF7CA9>.<1>,
> _NSURLErrorRelatedURLSessionTaskErrorKey=(
> "LocalDataTask <1BDB6BF8-A49A-44D9-93B9-A28E86DF7CA9>.<1>" ), NSLocalizedDescription=An SSL error has occurred and a secure
> connection to the server cannot be made.,
> NSErrorFailingURLKey=https://bank.gov.ua/,
> NSUnderlyingError=0x7f8878428810 {Error Domain=kCFErrorDomainCFNetwork
> Code=-1200 "(null)"
> UserInfo={_kCFStreamPropertySSLClientCertificateState=0,
> _kCFNetworkCFStreamSSLErrorOriginalValue=-9858, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9858}}, _kCFStreamErrorCodeKey=-9858}
> ---
>
> --- TLSv1.2 ATS Dictionary: {
> NSExceptionDomains = {
> "bank.gov.ua" = {
> NSExceptionMinimumTLSVersion = "TLSv1.2";
> };
> }; } Result : PASS
> ---
>
> --- TLSv1.1 ATS Dictionary: {
> NSExceptionDomains = {
> "bank.gov.ua" = {
> NSExceptionMinimumTLSVersion = "TLSv1.1";
> };
> }; } Result : PASS
> ---
>
> --- TLSv1.0 ATS Dictionary: {
> NSExceptionDomains = {
> "bank.gov.ua" = {
> NSExceptionMinimumTLSVersion = "TLSv1.0";
> };
> }; } Result : PASS
> ---
>
> ================================================================================
>
> Configuring PFS exceptions for bank.gov.ua
>
> --- Disabling Perfect Forward Secrecy ATS Dictionary: {
> NSExceptionDomains = {
> "bank.gov.ua" = {
> NSExceptionRequiresForwardSecrecy = false;
> };
> }; } Result : PASS
> ---
>
> ================================================================================
>
> Configuring PFS exceptions and allowing insecure HTTP for bank.gov.ua
>
> --- Disabling Perfect Forward Secrecy and Allowing Insecure HTTP ATS Dictionary: {
> NSExceptionDomains = {
> "bank.gov.ua" = {
> NSExceptionAllowsInsecureHTTPLoads = true;
> NSExceptionRequiresForwardSecrecy = false;
> };
> }; } Result : PASS
> ---
>
> ================================================================================
>
> Configuring TLS exceptions with PFS disabled for bank.gov.ua
>
> --- TLSv1.3 with PFS disabled ATS Dictionary: {
> NSExceptionDomains = {
> "bank.gov.ua" = {
> NSExceptionMinimumTLSVersion = "TLSv1.3";
> NSExceptionRequiresForwardSecrecy = false;
> };
> }; } Result : FAIL Error : Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the
> server cannot be made."
> UserInfo={NSErrorFailingURLStringKey=https://bank.gov.ua/,
> NSLocalizedRecoverySuggestion=Would you like to connect to the server
> anyway?, _kCFStreamErrorDomainKey=3,
> _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <AA01562F-24EA-4DC9-BCF7-6E9D625D9361>.<1>,
> _NSURLErrorRelatedURLSessionTaskErrorKey=(
> "LocalDataTask <AA01562F-24EA-4DC9-BCF7-6E9D625D9361>.<1>" ), NSLocalizedDescription=An SSL error has occurred and a secure
> connection to the server cannot be made.,
> NSErrorFailingURLKey=https://bank.gov.ua/,
> NSUnderlyingError=0x7f887a800470 {Error Domain=kCFErrorDomainCFNetwork
> Code=-1200 "(null)"
> UserInfo={_kCFStreamPropertySSLClientCertificateState=0,
> _kCFNetworkCFStreamSSLErrorOriginalValue=-9858, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9858}}, _kCFStreamErrorCodeKey=-9858}
> ---
>
> --- TLSv1.2 with PFS disabled ATS Dictionary: {
> NSExceptionDomains = {
> "bank.gov.ua" = {
> NSExceptionMinimumTLSVersion = "TLSv1.2";
> NSExceptionRequiresForwardSecrecy = false;
> };
> }; } Result : PASS
> ---
>
> --- TLSv1.1 with PFS disabled ATS Dictionary: {
> NSExceptionDomains = {
> "bank.gov.ua" = {
> NSExceptionMinimumTLSVersion = "TLSv1.1";
> NSExceptionRequiresForwardSecrecy = false;
> };
> }; } Result : PASS
> ---
>
> --- TLSv1.0 with PFS disabled ATS Dictionary: {
> NSExceptionDomains = {
> "bank.gov.ua" = {
> NSExceptionMinimumTLSVersion = "TLSv1.0";
> NSExceptionRequiresForwardSecrecy = false;
> };
> }; } Result : PASS
> ---
>
> ================================================================================
>
> Configuring TLS exceptions with PFS disabled and insecure HTTP allowed
> for bank.gov.ua
>
> --- TLSv1.3 with PFS disabled and insecure HTTP allowed ATS Dictionary: {
> NSExceptionDomains = {
> "bank.gov.ua" = {
> NSExceptionAllowsInsecureHTTPLoads = true;
> NSExceptionMinimumTLSVersion = "TLSv1.3";
> NSExceptionRequiresForwardSecrecy = false;
> };
> }; } Result : FAIL Error : Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the
> server cannot be made."
> UserInfo={NSErrorFailingURLStringKey=https://bank.gov.ua/,
> NSLocalizedRecoverySuggestion=Would you like to connect to the server
> anyway?, _kCFStreamErrorDomainKey=3,
> _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <BDF920C9-E44E-4DCD-BED7-94274E454AF4>.<1>,
> _NSURLErrorRelatedURLSessionTaskErrorKey=(
> "LocalDataTask <BDF920C9-E44E-4DCD-BED7-94274E454AF4>.<1>" ), NSLocalizedDescription=An SSL error has occurred and a secure
> connection to the server cannot be made.,
> NSErrorFailingURLKey=https://bank.gov.ua/,
> NSUnderlyingError=0x7f887a800390 {Error Domain=kCFErrorDomainCFNetwork
> Code=-1200 "(null)"
> UserInfo={_kCFStreamPropertySSLClientCertificateState=0,
> _kCFNetworkCFStreamSSLErrorOriginalValue=-9858, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9858}}, _kCFStreamErrorCodeKey=-9858}
> ---
>
> --- TLSv1.2 with PFS disabled and insecure HTTP allowed ATS Dictionary: {
> NSExceptionDomains = {
> "bank.gov.ua" = {
> NSExceptionAllowsInsecureHTTPLoads = true;
> NSExceptionMinimumTLSVersion = "TLSv1.2";
> NSExceptionRequiresForwardSecrecy = false;
> };
> }; } Result : PASS
> ---
>
> --- TLSv1.1 with PFS disabled and insecure HTTP allowed ATS Dictionary: {
> NSExceptionDomains = {
> "bank.gov.ua" = {
> NSExceptionAllowsInsecureHTTPLoads = true;
> NSExceptionMinimumTLSVersion = "TLSv1.1";
> NSExceptionRequiresForwardSecrecy = false;
> };
> }; } Result : PASS
> ---
>
> --- TLSv1.0 with PFS disabled and insecure HTTP allowed ATS Dictionary: {
> NSExceptionDomains = {
> "bank.gov.ua" = {
> NSExceptionAllowsInsecureHTTPLoads = true;
> NSExceptionMinimumTLSVersion = "TLSv1.0";
> NSExceptionRequiresForwardSecrecy = false;
> };
> }; } Result : PASS
> ---
>
> ============================================================================
Возможно ли для xcode игнорировать эту ошибку? Поскольку мое приложение работает нормально, данные загружаются. Просто метод в viewDidLoad иногда не загружает пользовательский интерфейс.