1

New to NSURLSessionTask in iOS11 is a progress property:

A representation of the overall task progress

@property(readonly, strong) NSProgress *progress;

When queried while at 781334 of 1025886 bytes, the output is like this:

<NSProgress: 0x1c0324ec0> : Parent: 0x0 / Fraction completed: 0.0000 / Completed: 0 of 1025886  
  <NSProgress: 0x1c0325140> : Parent: 0x1c0324ec0 / Fraction completed: 0.0000 / Completed: 781334 of -1  
  <NSProgress: 0x1c03251e0> : Parent: 0x1c0324ec0 / Fraction completed: 0.0000 / Completed: 0 of 100  

Note the fractionCompleted being 0.000 instead of 0.762.

When the data task finishes, the output of it's progress property looks like this:

<NSProgress: 0x1c4131440> : Parent: 0x0 / Fraction completed: 0.0000 / Completed: 5 of 1142597  
  <NSProgress: 0x1c4131580> : Parent: 0x1c4131440 / Fraction completed: 0.0000 / Completed: -1 of -1  

Note Completed: 5 of 1142597.

NSURLSessionTask's progress reporting appears to be totally useless. So in order to report progress to a UI in iOS11, I still have to write the same boilerplate code as before. So what is the purpose of this new property?

Mojo66
  • 1,109
  • 12
  • 21

1 Answers1

0

When reporting that bug with Apple, I created an example project, which is sitting here: https://github.com/mickeyl/iOS-Bug-Example-Projects/tree/master/NSURLSessionTask-Progress-Broken

Here is an excerpt of a log created with the sample project above:

2018-06-15 12:02:17.641650+0200 NSURLSessionTask-Progress-Broken[74670:2636851] Progress = <NSProgress: 0x600000131800> : Parent: 0x0 / Fraction completed: 0.4588 / Completed: 5 of 100  
  <NSProgress: 0x600000131440> : Parent: 0x600000131800 / Fraction completed: 0.4303 / Completed: 462000019 of 1073741824
2018-06-15 12:02:17.641917+0200 NSURLSessionTask-Progress-Broken[74670:2636851] Progress = <NSProgress: 0x600000131800> : Parent: 0x0 / Fraction completed: 0.4588 / Completed: 5 of 100  
  <NSProgress: 0x600000131440> : Parent: 0x600000131800 / Fraction completed: 0.4303 / Completed: 462002915 of 1073741824
2018-06-15 12:02:17.642193+0200 NSURLSessionTask-Progress-Broken[74670:2636851] Progress = <NSProgress: 0x600000131800> : Parent: 0x0 / Fraction completed: 0.4588 / Completed: 5 of 100  
  <NSProgress: 0x600000131440> : Parent: 0x600000131800 / Fraction completed: 0.4303 / Completed: 462005811 of 1073741824
2018-06-15 12:02:17.642476+0200 NSURLSessionTask-Progress-Broken[74670:2636851] Progress = <NSProgress: 0x600000131800> : Parent: 0x0 / Fraction completed: 0.4588 / Completed: 5 of 100  
  <NSProgress: 0x600000131440> : Parent: 0x600000131800 / Fraction completed: 0.4303 / Completed: 462008707 of 1073741824
2018-06-15 12:02:17.642828+0200 NSURLSessionTask-Progress-Broken[74670:2636851] Progress = <NSProgress: 0x600000131800> : Parent: 0x0 / Fraction completed: 0.4588 / Completed: 5 of 100  
  <NSProgress: 0x600000131440> : Parent: 0x600000131800 / Fraction completed: 0.4303 / Completed: 462014499 of 1073741824
2018-06-15 12:02:17.643083+0200 NSURLSessionTask-Progress-Broken[74670:2636851] Progress = <NSProgress: 0x600000131800> : Parent: 0x0 / Fraction completed: 0.4588 / Completed: 5 of 100  
  <NSProgress: 0x600000131440> : Parent: 0x600000131800 / Fraction completed: 0.4303 / Completed: 462017395 of 1073741824
2018-06-15 12:02:17.643344+0200 NSURLSessionTask-Progress-Broken[74670:2636851] Progress = <NSProgress: 0x600000131800> : Parent: 0x0 / Fraction completed: 0.4588 / Completed: 5 of 100  
  <NSProgress: 0x600000131440> : Parent: 0x600000131800 / Fraction completed: 0.4303 / Completed: 462020291 of 1073741824
2018-06-15 12:02:17.643611+0200 NSURLSessionTask-Progress-Broken[74670:2636851] Progress = <NSProgress: 0x600000131800> : Parent: 0x0 / Fraction completed: 0.4588 / Completed: 5 of 100  
  <NSProgress: 0x600000131440> : Parent: 0x600000131800 / Fraction completed: 0.4303 / Completed: 462023187 of 1073741824
2018-06-15 12:02:17.643878+0200 NSURLSessionTask-Progress-Broken[74670:2636851] Progress = <NSProgress: 0x600000131800> : Parent: 0x0 / Fraction completed: 0.4588 / Completed: 5 of 100  
  <NSProgress: 0x600000131440> : Parent: 0x600000131800 / Fraction completed: 0.4303 / Completed: 462026083 of 1073741824

[...]

2018-06-15 12:03:29.216655+0200 NSURLSessionTask-Progress-Broken[74670:2636247] Progress = <NSProgress: 0x600000131800> : Parent: 0x0 / Fraction completed: 1.0000 / Completed: 5 of 100  
  <NSProgress: 0x600000131440> : Parent: 0x600000131800 / Fraction completed: 1.0000 / Completed: 1073727891 of 1073741824
2018-06-15 12:03:29.217201+0200 NSURLSessionTask-Progress-Broken[74670:2636854] Progress = <NSProgress: 0x600000131800> : Parent: 0x0 / Fraction completed: 1.0000 / Completed: 5 of 100  
  <NSProgress: 0x600000131440> : Parent: 0x600000131800 / Fraction completed: 1.0000 / Completed: 1073730787 of 1073741824
2018-06-15 12:03:29.217407+0200 NSURLSessionTask-Progress-Broken[74670:2636854] Progress = <NSProgress: 0x600000131800> : Parent: 0x0 / Fraction completed: 1.0000 / Completed: 5 of 100  
  <NSProgress: 0x600000131440> : Parent: 0x600000131800 / Fraction completed: 1.0000 / Completed: 1073733683 of 1073741824
2018-06-15 12:03:29.217889+0200 NSURLSessionTask-Progress-Broken[74670:2637014] Progress = <NSProgress: 0x600000131800> : Parent: 0x0 / Fraction completed: 1.0000 / Completed: 5 of 100  
  <NSProgress: 0x600000131440> : Parent: 0x600000131800 / Fraction completed: 1.0000 / Completed: 1073739475 of 1073741824
2018-06-15 12:03:29.218147+0200 NSURLSessionTask-Progress-Broken[74670:2637014] Progress = <NSProgress: 0x600000131800> : Parent: 0x0 / Fraction completed: 1.0000 / Completed: 100 of 100

Here we can observe that – for some reason – for one NSURLSessionTask there is a parent and a child NSProgress created. While the child progress contains the proper information, the parent process seems to stick with 5 / 100 units for most of the time. At least it gets the fractionCompleted somewhat right.

So: When sticking to the child NSProgress the progress property is somewhat useful.

Unfortunately I need to support iOS all the way down to 9, which is why I will have to create my own substitute anyways.

DrMickeyLauer
  • 4,455
  • 3
  • 31
  • 67