NSURLSessionDownloadTask move temporary file

Viewed 1485

I'm trying to reach the file which I was downloading earlier by NSURLSession. It seems I can't read the location of the file, even though I'm doing it before delegate method ends (as the file is temporary).

Still, I'm getting nil when trying to access the data under location returned from NSURLSession delegate and error 257.

The code goes as following:

- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location {
    NSError *movingError = nil;
    NSData *fileData = [NSData dataWithContentsOfFile:location.path options:0 error:&movingError]; // is nil
    NSLog(@"%@", movingError); // is error 257
}

What's wrong with this code..? I saw similar questions NSURLSessionDownloadTask - downloads but ends with error and iPhone - copying a file from resources to Documents gives an error but these completely doesn't apply to my case.

-- edit --

I've created a new project and pasted the very same code. It works... So:

1) In my project I'm receiving error 257, probably some configuration of the project is invalid or the fact I'm using backgroundTasks somewhere else in the app messes things up

2) Same as in 1 happens if I put the source files of this download to the external framework linked in by Carthage

3) On demo project I created (copy-pasted files used in 1 & 2) everything works corretly.

If someone has an idea what can cause the fact it isn't working - would be awesome.

2 Answers

I found same error code 257 from online users feedback.In the error scene, the location always refers to a strange bundle identifier:com.sdyd.SDMobileMixSmart. And I guess this's an apple system bug.

Related