Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C - HTTP load failed (error code: -1004 [1:61]) for Task in iOS11

Tags:

http

ios11

I'm trying to perform a datatask with URLSession, when I run it on 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 Simulator it doesn't happen.

What's causing it or how to fix it?

Here'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;
}
like image 633
Vagner Machado Avatar asked Sep 22 '17 19:09

Vagner Machado


1 Answers

Make sure 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/

Verify that you are not using cyphers hashes and protocols that are no longer supported by apple.

IOS 11 no longer supports these:

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 whitelist the domain by using the NSAppTransportSecurity property in you application plist file.

like image 95
Wayne Avatar answered Nov 18 '22 13:11

Wayne