I managed to solve it. I am not saying that my decision is a decision , but it is a .
The behavior I am experiencing is that iOS 7 and iOS 8 prioritize properties in different ways. I have two places to set these timeout properties, NSURLSessionConfiguration and in NSMutableURLRequest . iOS 7 does not care about query properties, and iOS 8 cannot care about configuration properties. My solution now looks like this:
NSURLSessionConfiguration *sessionConfig; if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { sessionConfig = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:identifier]; } else { sessionConfig = [NSURLSessionConfiguration backgroundSessionConfiguration:identifier]; } if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0) { sessionConfig.timeoutIntervalForRequest = 5 * 60.0; } _backgroundSession = [NSURLSession sessionWithConfiguration:sessionConfig delegate:self delegateQueue:nil]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL]; if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { request.timeoutInterval = 5 * 60.0; } NSURLSessionDownloadTask *downloadTask = [_backgroundSession downloadTaskWithRequest:request];
I think you can simply not do systemVersion checks and set both properties to the same value. Although I firmly believe that less code is more, I find it even stronger without affecting states that should not be affected. However, I would like to hear the opinions of people . And if anyone has a better solution, please share .
One more thing. The repeating part will continue until timeoutIntervalForResource reaches the default value of 7 days according to the documentation. I reduced it to 10 minutes.
sessionConfig.timeoutIntervalForResource = 10 * 60;
I am not saying that this should be changed. This is the decision we made for our particular environment setup.
Update
We changed timeoutIntervalForResource to the default value of 7 days. For example, we have customers in China, and some of them are really poorly connected. The 10 minute master limit was just stupid.
Be sure to check out Sunkas answer for better code quality. However, my code snippet extends to different classes, so I cannot reuse this approach 100%.
source share