The behavior of a task in the session depends on three things: the type of session, the type of task, and whether the app is running in the foreground when the task is created.
Types of Sessions
We configure the nsurlsession by configuring the Nsurlsessionconfiguration object class. There are three types of session:
1, General mode: Similar to other download URL basic method, you can use cached cache, Cookie, authentication.
2, timely mode: Do not use cache, cookies, authentication.
3, the background mode: in the background to complete the upload download, the creation of configuration objects need to give a nsstring ID used to chase the completion of the session is which.
Type of Task:
1.Nsurlsessiondatatask: Use the NSData object to send the accepted data, because the data task does not store the data in the file, so the background mode of the session is not supported.
2,Nsurlsessiondownloadtask: Receive data in the form of files, and support background download when the app is not running.
3,Nsurlsessionuploadtask: Usually send (upload) data in the form of files, and when the app is not running, support the background to bed.
Considerations for background transfers:
The Nsurlsession class supports background transfers when your app is paused. Background transfers are only used by session objects configured with background mode.
Some features are not available because the actual transfer is a separate process and the cost of restarting the app is more expensive:
1, the session must implement an event delivery agent (for upload and download, proxy as the same intermediate transfer method)
2. Only HTTP and HTTPS protocol support (no custom protocol)
3. Only upload and download tasks are supported (no data tasks)
4. redirect
5. When the application is started in the background, the public properties of the configuration object are considered to be true.
iOS Learning Note--nsurlsession