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;
}
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:
Hashes:
Key Sizes:
Protocols:
If they are not supported you can whitelist the domain by using the NSAppTransportSecurity property in you application plist file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With