New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue5-4-from-NSURLConnection-to-NSURLSession 's issue. #24

Closed
FangYiXiong opened this Issue Apr 8, 2014 · 3 comments

Comments

Projects
None yet
4 participants
@FangYiXiong
Copy link

FangYiXiong commented Apr 8, 2014

in the paragraph "Download requests take a request as well...." of section Constructors in article issue-5-4 I found something hard to be understood.

  1. it says in the last: "...the completion handler to move the file from its temporary location to a permanent location, which is then the return value of the block: ". But the block here actually has no return value. so the code below will not be compilable.
  2. I also don't get the idea of the code of the block below that is using the [response URL] instead of the return value NSURL * location. isn't the latter to be the actual temp file's URL?
@chriseidhof

This comment has been minimized.

Copy link
Contributor

chriseidhof commented Aug 11, 2014

Hm, I see what you mean. Probably the block needs to move the file there.

@mattt, could you have a look at this? If not, I could also update it!

@mattt

This comment has been minimized.

Copy link

mattt commented Aug 11, 2014

  1. it says in the last: "...the completion handler to move the file from its temporary location to a permanent location, which is then the return value of the block: ". But the block here actually has no return value. so the code below will not be compilable.

Indeed, I had mixed that up with what AFNetworking does for download tasks. The code should be:

NSURLSessionDownloadTask *downloadTask = [session downloadTaskWithRequest:request
                                                         completionHandler:
    ^(NSURL *location, NSURLResponse *response, NSError *error) {
        NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
        NSURL *documentsDirectoryURL = [NSURL fileURLWithPath:documentsPath];
        NSURL *documentURL = [documentsDirectoryURL URLByAppendingPathComponent:[response 
suggestedFilename]];
        [[NSFileManager defaultManager] moveItemAtURL:location
                                                toURL:documentURL
                                                error:nil];
    }];

The updated paragraph should omit ", which is then the return value of the block".

  1. I also don't get the idea of the code of the block below that is using the [response URL] instead of the return value NSURL * location. isn't the latter to be the actual temp file's URL?

location is a temporary file in a temporary directory. The purpose of this completion handler is to move it to its final directory and filename, which should be derived from the suggestedFilename of the response.

floriankugler pushed a commit that referenced this issue Oct 9, 2014

@chenzilu1990

This comment has been minimized.

Copy link

chenzilu1990 commented Dec 2, 2015

o,o,soga

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment