iOS Learning Note--nsurlsession

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.