Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AFNetworking stopped working under iOS 6

I've noticed recently, that my code, that uses AFNetworking (latest version from master branch) stopped working properly under iOS 6. Here's my code:

httpClient = [AFHTTPClient clientWithBaseURL:[NSURL URLWithString:baseURL]];
httpClient.operationQueue.maxConcurrentOperationCount = 1;

where httpClient is a class variable.

Next, I'm creating a request:

NSMutableURLRequest *signInRequest = [httpClient requestWithMethod:@"POST" path:@"/user/register" parameters:dataToSend];
signInRequest.timeoutInterval = 15.0;
signInRequest.cachePolicy = NSURLRequestReloadIgnoringLocalAndRemoteCacheData;

AFJSONRequestOperation *signInOperation = [AFJSONRequestOperation JSONRequestOperationWithRequest:signInRequest success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON)
{
    // Blah
}
    failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON)
{
    // Blah
}];

[httpClient enqueueHTTPRequestOperation:signInOperation];

All the other requests are constructed similarly. The first enqueued operation works well, I can get into success handler block. However, next calls to other requests are finished with fail handler and request timeout error, no matter how big is timeout value I choose.

I have done the same calls using plain NSURLConnection, writing a tons of code :), with success, requests were processed properly.

I switched to iOS 5 device, and the code above works fine.

I switched to 3G connection (iOS 6), and the code above works.

It seems like I have this problem only on WiFi connections (except the case when I'm in the same subnet with my REST server.)

Any thoughts on this?

Thank you in advance.

like image 208
anticyclope Avatar asked Oct 08 '12 09:10

anticyclope


1 Answers

It seems you also posted an issue on AFNetworking's github and found the solution yourself :)!

It seems like iOS 6 changes something to TCP implementation or something. I moved server to third-party hosting and it is working now.

For future readers, the issue can be found here.

like image 58
Tieme Avatar answered Nov 13 '22 13:11

Tieme