The essential reason why iOS network transmission delegate not be triggered

Source: Internet
Author: User

Nsurlsession altogether there are four kinds of delegate (post table with session and Sessiontask classification form)

Nsurlsessiondelegate, Nsurlsessiondownloaddelegate,

Nsurlsessiontaskdelegate, Nsurlsessiondatadelegate

Nsurlsession set delegate when only set a delegate, it already represents four delegate all set. Sometimes some delegate are not triggered because these four kinds of delegate respond to different urlsession types and urlsessiontask types, meaning that different types only trigger part of those delegate, Rather than triggering all delegate.

Examples are as follows

1. Trigger Nsurlsessiondatadelegate

Use function Datatask to receive data

-(void) Urlsession: (Nsurlsession *) session Datatask: (Nsurlsessiondatatask *) Datatask Didreceivedata: ( NSData *) data

The code for the Nsurlsession section is as follows

1     nsurlsessionconfiguration* ephconfiguration=[nsurlsessionconfiguration defaultsessionconfiguration]; 2     Delegate : Self delegatequeue:[nsoperationqueue mainqueue]]; 3     nsurl* url=[nsurl urlwithstring:@ "http://www.example.com/external_links/01.png" ];   4      nsurlsessiondatatask* datatask=[session Datataskwithurl:url]; 5     [Datatask resume];

2. Trigger Nsurlsessiondownloaddelegate

Using function Downloadtask to accept data

-(void) Urlsession: (Nsurlsession *) session Downloadtask: (Nsurlsessiondownloadtask *) downloadtask Didfinishdownloadingtourl: (Nsurl *) location

The code for the Nsurlsession section is as follows

1     nsurlsessionconfiguration* ephconfiguration=[nsurlsessionconfiguration defaultsessionconfiguration]; 2     Delegate : Self delegatequeue:[nsoperationqueue mainqueue]]; 3     nsurl* url=[nsurl urlwithstring:@ "http://www.example.com/external_links/01.png" ];   4      nsurlsessiondownloadtask* datatask=[session Downloadtaskwithurl:url]; 5     [Datatask resume];

The main difference between the two pieces of code is that the different types of nsurlsessiontask cause different delegate to be triggered

Schedule

Categories of urlsession

Session Type Features explained
Default Session Can be cached to disk, can pause
Ephemeral Session Short process, stored in RAM
Background Session Can background Running, other features similar to the default Session

Categories of Sessiontask

Sessiontask Type Features explained
Data Tasks Interaction of small files
Download Tasks Download type
Upload Tasks Upload type

The essential reason why iOS network transmission delegate not be triggered

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.