That is an issue of iOS
more info here: https://devforums.apple.com/message/926113#926113
Any solutions / workarounds? I'm seeing the same problem.
Tested using a basic [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"..."]] and -downloadTaskWithRequest:
A couple of observations:
The very first time the app calls -downloadTaskWithRequest: it works perfectly.
Subsequent calls to -downloadTaskWithRequest: return nil, until the app is killed.
Now we have only one workaround: Multiple calls of task creation method. And it works for us! Usually it has effect on second-third time.
_task = [[self downloadSession] downloadTaskWithRequest:request completionHandler:nil];
// Workaround to solve issue https://devforums.apple.com/message/926113
// Occurs consistently on iOS 7.0.5 and lower
// Sometimes _task may not be initialized, so we try again:
if (!_task)
{
for (int i = 0; i < 5; i++)
{
NSLog(@"%s, attempt #%d to recreate download task", __func__, i + 1);
_task = [[self downloadSession] downloadTaskWithRequest:request completionHandler:nil];
if (_task)
{
break;
}
}
}