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