Objective-C - iOS11中的任务的HTTP加载失败(错误代码:-1004 [1:61])

Vag*_*ado 6 http ios11

我正在尝试使用URLSession执行数据任务,当我在iOS11设备(iPhone 5S)上运行它时出现控制台错误:

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
Run Code Online (Sandbox Code Playgroud)

在模拟器上运行它不会发生.

是什么导致它或如何解决它?

这就是我正在做的事情

#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;
}
Run Code Online (Sandbox Code Playgroud)

Way*_*yne 6

通过运行以下命令确保支持URL:

curl -v https://example.com/mobile/services/ecard/

nscurl --verbose --ats-diagnostics https://example.com/mobile/services/ecard/
Run Code Online (Sandbox Code Playgroud)

确认您没有使用apple不再支持的密码哈希和协议.

IOS 11不再支持这些:

Cyphers:

  • RC4
  • 3DES-CBC
  • AES-CBC

哈希表:

  • MD5
  • SHA-1

主要尺寸:

  • <2048位RSA Pub Keys

协议:

  • HTTP://
  • 在SSLv3
  • TLS 1.0
  • TLS 1.1

如果不支持它们,则可以使用应用程序plist文件中的NSAppTransportSecurity属性将域列入白名单.