Objective-C - HTTP loading error (error code: -1004 [1:61]) for the task in iOS11

I am trying to execute a datatask with a URLSession, when I run it on an iOS11 device (iPhone 5S), I get a console error:

2017-09-22 15:22:17.942015-0300 app[1355:283536] TIC TCP Conn Failed [3:0x1c417af40]: 1:61 Err(61) 2017-09-22 15:22:17.943698-0300 app[1355:283536] Task <A32F0275-75C3-4F64-AB92-2E37527AB813>.<0> HTTP load failed (error code: -1004 [1:61]) 2017-09-22 15:22:17.945265-0300 app[1355:283676] NSURLConnection finished with error - code -1004 

Running on the simulator does not occur.

What causes this or how to fix it?

That's what I'm doing

 #define kEcardURL @"https://example.com/mobile/services/ecard/" - (void)doSomething { //Params Configuration NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys: [oauth.userData valueForKey:@"wsuserid"], @"token", nil]; NSString *path = @"fotoCartao"; NSData* params = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil]; NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", kEcardURL, path]]; NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url]; [urlRequest setHTTPMethod:@"POST"]; [urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [urlRequest setHTTPBody:params]; NSURLSessionDataTask *dataTask = [[self session] dataTaskWithRequest:urlRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; if ([data length] > 0 && error == nil) { if ([httpResponse statusCode] == 200) { //do stuff } } }]; [dataTask resume]; } } - (NSURLSession *)session { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ // Session Configuration NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration]; // Initialize Session _session = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: nil delegateQueue: [NSOperationQueue mainQueue]]; }); return _session; } 
+5
source share
2 answers

Verify that the URL is supported by running the following commands:

 curl -v https://example.com/mobile/services/ecard/ nscurl --verbose --ats-diagnostics https://example.com/mobile/services/ecard/ 

Make sure you do not use encryption hashes and protocols that are no longer supported by the apple.

IOS 11 no longer supports them:

Cyphers:

  • RC4
  • 3DES-CBC
  • AES-CBC

Hashes:

  • MD5
  • SHA-1

Key sizes:

  • <2048-bit RSA Pub Keys

Protocols:

  • http: //
  • SSLv3
  • TLS 1.0
  • TLS 1.1

If they are not supported, you can redirect the domain using the NSAppTransportSecurity property in your application plist file.

+3
source

[SOLVED] This was caused by server-side version of TLS (1.1). Adding an entry to NSAppTransportSecurity, Wayne said, solved the problem.

0
source

Source: https://habr.com/ru/post/1272050/


All Articles