NSURLSession didSendBodyData less called on iOS10

Hey,


i'm uploading data (mostly about 1MB files) with a uploadTaskWithStreamedRequest.


To give the user feedback about the upload progress i'm using didSendBodyData-delegate:

- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didSendBodyData:(int64_t)bytesSent totalBytesSent:(int64_t)totalBytesSent totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend
{
    if (task == uploadTask) {
        double progress = (double)totalBytesSent / (double)totalBytesExpectedToSend;
        dispatch_async(dispatch_get_main_queue(), ^{
            hud.progress = progress;
        });
    }
}


Before iOS 10 the progressbar smoothly growed, since iOS10 the delegate seems to be just called twice, once at the beginning and last on nearly finished upload process. If i run it on the simulator against iOS 9.3 its smooth again.


Did I miss any change?


Best regards,

Nils

Replies

This delegate method is called as data is passed from user space to the kernel. Modern systems can have very large buffers within the kernel, which reduces the utility of this callback when uploading small files because the entire file fits into the kernel socket buffer. If you switch to a much bigger file, say 100 MB, what do you see?

[Which isn’t to say that you should switch to 100 MB files in your real app; this is just a diagnostic test.]

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"