Search code examples
iosnsurl

About NSURLSessionTask and "resume"


I wish to clarify the meaning of "resume". It is used to start a session task according to Apple's documentation.

My question is if the task is "resume" the second time before the first "resume" completes its operation, does the second "resume" would just ask the task to continue work from the first call without starting from the very beginning?

That is, if the task has been started and paused for whatever reasons the second "resume" call would just resume what the task had been doing.

Secondly, if the task has not been stopped or paused at all, the second "resume" call would have no effect and the task would just continue to do what it is supposed to do ...

Hope that somebody who knows if the above 2 assumptions are correct can give some help.


Solution

  • An NSURLSessionTask can be in one of four states;

    • Active
    • Suspended
    • Cancelled
    • Completed

    Calling resume only has an effect if the task is currently suspended.

    A task starts in the suspended state, so you must call resume initially to start it.

    Calling resume on an active, completed or cancelled task has no effect.

    You can suspend a task by calling suspend.

    The effect of calling resume on a suspended task depends on the type of task;

    • An NSURLSessionDownloadTask can be resumed from where it was suspended.
    • All other task types are restarted.