web123456

iOS small skills: HTTPS problem analysis summary: 1, NSURLSessionTask finished with error - code: -1005 (request timeout) 2, Error Code = -999

Article Catalog

  • introductory
  • I、NSURLSessionTask finished with error - code: -1005(Request timeout)
  • II. Solution for Error Code=-999 cancelled
    • 2.1 Analysis of causes
    • 2.2. Solution: Set `securityPolicy` to allow no SSL certificate validation
  • III、Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer corre

introductory

  • -1005 (request timeout)
  • -999 cancelled solution: Allow no SSL certificate validation, to avoid SSL certificate expiration request errors!
  • Dictionary for ConCurrentDictionary, thread-safe

I、NSURLSessionTask finished with error - code: -1005(Request timeout)

Solution, change the timeout

-     = 5.0;
+     = 30.0;

  • 1
  • 2
  • 3

II. Solution for Error Code=-999 cancelled

  • Solution for iOS HTTPS request Error Code=-999 canceled: [Allow not to validate SSL certificate, to avoid SSL certificate expiration caused by the request error].

be directed against load failed with error Error Domain=NSURLErrorDomain Code=-999 "Cancelled"Wrong solutionThe solution:

  • Allow not to validate SSL certificates, to avoid the SSL certificate expiration of the request error report
  • Timely deployment of valid certificates in the environment in which they are used

2.1 Analysis of causes

SSL certificateFailed, causing the problem.

  • evaluateServerTrust:forDomain:
/**
 Whether or not the specified server trust should be accepted, based on the security policy.

 This method should be used when responding to an authentication challenge from a server.

 @param serverTrust The X.509 certificate trust of the server.
 @param domain The domain of serverTrust. If `nil`, the domain will not be validated.

 @return Whether or not to trust the server.
 */
- (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust
                  forDomain:(nullable NSString *)domain;

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

在这里插入图片描述

When the certificate is invalid, the above method returns NO, thus executing the

                disposition = NSURLSessionAuthChallengeCancelAuthenticationChallenge;

  • 1
  • 2

As a result, the current request is canceled.

2.2. Solution: SettingssecurityPolicyAllow no SSL certificate validation

  • set upsecurityPolicy

AFSecurityPolicy *securityPolicy = [AFSecurityPolicy defaultPolicy];
securityPolicy.validatesDomainName = NO;
securityPolicy.allowInvalidCertificates = YES;
manager.securityPolicy = securityPolicy;
  • 1
  • 2
  • 3
  • 4
  • 5

III、Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection’s state is no longer corre

  • Error message:
{
	message = Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.;
	data = <null>;
	code = 500;
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • Solution: The exact solution depends on the code
    For example: the interface corresponds to the server side using .
Dictionary for ConCurrentDictionary, thread-safe

  • 1
  • 2