Question

I have problem with NSURLSessionDownloadTask in my app I create few hundreds download task with code:

NSURLSessionDownloadTask * task = [_urlSession downloadTaskWithURL:downloadUrl];
NSLog(@"session: %@, download task %@ for url: '%@'",_urlSession, task, downloadUrl);
if (!task)
{
     NSLog(@"ooops no task");
}else
{

} 

In xcode console I have messages like this one:

2014-03-28 11:23:39.297 MYAPP[3838:60b] session: <__NSCFURLSession: 0x19471e70>, download task (null) for url: 'http://xxx.cloudfront.net/seminarcontent/nsm_photos_11_24d8505e-4ddd-4e9b-baef-a90d5e322702.jpg'

Also in Organizer's console I see this message:

nsnetworkd[322] <Error>: __NSCFLocalDownloadFile: error 2 creating temp file: /private/var/mobile/Applications/MYAPPGUID-BD21-4C5A-8DB6-845D80BE75E3/Library/Caches/com.apple.nsnetworkd/CFNetworkDownload_R91Hqn.tmp

NSURLSession created before with:

_urlSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration  backgroundSessionConfiguration:sessionIdenttificator] delegate:self delegateQueue:nil];

All urls are valid and this happens only if I start download just after app launch

Please share your ideas about my problem. Thanks in advance.

Update:

I also added check for cache directory, for sure that is exist before I started download but nothing changed

Edit

Additional info, I cant reproduce the bug in simulator, or on device in debug mode (with breakpoints enabled).

Was it helpful?

Solution

Finally, after few days of debugging a found the partial solution.

  @synchronized(_urlSession)
  {
      task = [_urlSession downloadTaskWithURL:downloadUrl];
  }

I added lock to my code and now everything works as should, but I guess this not a solution just a way to avoid problem.

Thanks to @Jody Hagins for very helpful comments.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top