Hi Daryle,

Receiving a nil error on success is expected— please refer to NSURLSession.h:

/* Sent as the last message related to a specific task.  Error may be
 * nil, which implies that no error occurred and this task is complete. 
 */
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task
                           didCompleteWithError:(NSError *)error;

In the case of a successful download, your delegate should receive:

-URLSession:downloadTask:didFinishDownloadingToURL:

with the location of the downloaded file, followed by:

-URLSession:task:didCompleteWithError:

with a nil error parameter.

- Dan

> On Apr 7, 2015, at 11:44 PM, Daryle Walker <[email protected]> wrote:
> 
>> On Apr 7, 2015, at 3:10 PM, Daryle Walker <[email protected]> wrote:
>> 
>> I’m using NSURLSessionDownloadTask in a command-line tool. I just adapted it 
>> to run multiple URLs to download. The loops and task work when I enter a 
>> single URL. When I enter two, the shorter file is downloaded, but the "- 
>> URLSession: task: didCompleteWithError:” is called for the second URL, and 
>> the error parameter gets NIL as its value. I have a run loop in the main 
>> function, and I call “resume” on both tasks. Am I supposed to run the 
>> success code when I get a NIL error? But there’s a separate method for 
>> successful downloads (and that other method tells me where the new file is)! 
>> The two URLs download when I call the tool for them separately.
>> 
>> I only have two delegate methods defined; the other is “- URLSession: 
>> downloadTask: didFinishDownloadingToURL:”.
> 
> I changed my mass-resume function to only resume the first download task. The 
> next task is resumed within the completion or error handler. The last task 
> calls “finishTasksAndInvalidate” for the session. The same error still 
> happens. (The actual crash is caused by my code storing the error object, and 
> the dictionary craps out when trying to save a NIL object.)
> 
> If it makes a difference, the session is configured to use the main thread, 
> since tools don’t need extra threads (no GUI).
> 
> It seems that something is getting purged on the first competition/error and 
> never reinitialized for subsequent tasks.
> 
> — 
> Daryle Walker
> Mac, Internet, and Video Game Junkie
> darylew AT mac DOT com 
> 
> 
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Macnetworkprog mailing list      ([email protected])
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/macnetworkprog/dvinegrad%40apple.com
> 
> This email sent to [email protected]

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/macnetworkprog/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to