AFNetworking with request error code 999

In my case iOS 10 SDK's caused AFNetworking error code -999. If you're trying to reach a server that has SSL and you don't want to check it out, add some privacy Policy to Afnetworking

AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
securityPolicy.allowInvalidCertificates = YES;

[securityPolicy setValidatesDomainName:NO];

That's error -999, not 999. That is NSURLErrorCancelled. Your request has been cancelled before it can be completed.

Looking at your code, you aren't retaining the AFHTTPSessionManager *manager anywhere. This means that the manager will be disposed as soon as +simpleRequest returns. I'm guessing that this is what is cancelling your request.

You need to save the manager so that it lives for the full duration of the request. Save it in a property somewhere.


In my case iOS 9 SDK's "App transport security" cause AFNetworking error code : -999. If you're trying to reach a server that doesn't have a SSL add keys like screenshot below.

enter image description here