This seems like normal behavior, but Appleβs clearer documentation will be helpful in figuring out what we see.
The apple documentation does not provide a detailed explanation of how the suspension works, or when it should be used. However, my view (based on testing and research) is that suspend() should only be used to load a job. Data tasks should only use resume() (to run the task) and cancel() when necessary.
My testing using Xcode and Charles Proxy showed that a suspended data task does not affect network traffic, as indicated in the Apple documentation. In other words, network traffic is created.
I observed two things using pause and data tasks:
1) If it is called immediately after resuming, it does not affect the data task. It does not suspend network traffic and does not prohibit network or server problems; a successful response was received in the callback.
2) If he called the dispatch.asyncAfter callback, he still does not suspend network traffic, however, the callback receives a "timeout request" error instead of a successful response. According to Charles Proxy, the request was successful. It is this result that makes me think that suspend() should not be used with data tasks. The result of this callback is practically useless, in my opinion.
Cancel a task with data:
cancel() works as expected. The client (you) closes the connection before receiving a complete response from the server. This can be done immediately after calling resume() or later (before the request completes, of course).
source share