NSURLSession
works at an "upper" level, and is made to be more simple for the developer than using NSURLConnection
.
I made some tests and I think that there is no possibility to control the runloop and the mode of NSURLSession
, because they seems to be managed by an external daemon and not by your App (I tested only with NSURLSessionDownloadTask
).
Do this simple test:
- download and execute this Github project
- start a download
- open the "downloads" controller to see the state of your download
- pause the app
- wait a moment
- unpause the app
you will see that the download has been continued while your app was paused, so when you start a NSURLSession
the control is passed to the system, outside your app: it means that the main part of the work doesn't take place in an internal runLoop.
The only thing you have control on, is the serial queue on which the delegate calls are dispatched (passed back to your application). The delegate calls are queued for execution (on the main or on a background thread, you can choose it), since NSOperationQueue
use Grand Central Dispatch to queue the calls, I'm not sure about the runloop mode used for this, but I think this is a good starting point to continue your researches.
EDIT:
If I remember correctly, dispatch calls made on background threads are made on threads where a runloop is not running. In fact, if you add this line
NSLog(@"%@", [[NSRunLoop currentRunLoop] currentMode]);
on one of the delegate methods of the FLDownloader
class in the previous project, you will see that there is no run mode (nil), this happens when the runloop is not running.