Scooter
Scooter

Reputation: 4166

iOS 8 causing trouble with NSURLSession

I have a fairly complex iPad app that has been live in the app store for months that makes extensive use of NSURLSession to interact with .php files on a web server to read and write files to the web server. The networking portion of the app now either works intermittently (or not at all) on devices that are running iOS 8. Has anyone seen anything similar occur with their app?

I will start the painstaking forensics this weekend, but just thought I would ask here first to see if anyone else had run into this.

I haven't yet found any known issues in the Apple Docs concerning NSURLSession and iOS 8. I have recompiled the app with XCode 6.0.1 and run it on a test device and it still exhibits the same behavior.

Upvotes: 0

Views: 1264

Answers (1)

Scooter
Scooter

Reputation: 4166

I found the solution to this, but can't explain why it is a solution. This is the code I use to set up the NSURLSession:

NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration];
sessionConfig.allowsCellularAccess = YES;
sessionConfig.timeoutIntervalForRequest = 30;
sessionConfig.timeoutIntervalForResource = 60;
sessionConfig.HTTPMaximumConnectionsPerHost = 1;
sessionConfig.URLCache = NULL;

//Create the session with the newly created sessionConfig.
session = [NSURLSession sessionWithConfiguration:sessionConfig delegate:self delegateQueue:nil];

This line of code was the culprit

sessionConfig.HTTPMaximumConnectionsPerHost = 1;

I simply increased 1 to 10 and viola, it works correctly on iOS 8 as well now. I have no idea why this runs perfectly on iOS 7 with the value set to 1, but not on iOS 8. The only thing that I can think of is that maybe Apple changed the internal workings of NSURLSession.

Upvotes: 2

Related Questions