> On Apr 9, 2015, at 12:37 AM, Daryle Walker <dary...@mac.com> wrote:
> 
> NSProgress, one of those APIs too new to be well used. Does anyone know how 
> to use it with a downloading task?

Hey! I just started using NSProgress too, yesterday.

> One problem is that it’s a secret which API groups support NSProgress.

…and I just ran into this too. The really annoying part is when you make an 
NSProgress current because you want to add a child, but while it’s current you 
call a system API that itself uses NSProgress, so you end up adding multiple 
children to your top-level object, which completely screws up the 
fractionComplete calculation.

> But I don’t know if NSFileManager supports NSProgress, nor where to insert 
> manual calls if it doesn’t.

Apparently it does; it’s the API that I alluded to above. At least, the 
-createFileAtPath: method uses NSProgress.

NSFileManager isn’t the best API for writing a downloaded file, though. If 
you’re downloading incrementally, use NSFileHandle or something like it (or 
just plain old fopen / fwrite / fclose.)

You’d put the NSProgress calls in the NSURLSession delegate methods. Every time 
you receive a chunk of data, first write it to the file, then add the length of 
the chunk to the progress’s completedUnitCount.

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

This email sent to arch...@mail-archive.com

Reply via email to