Session Download Task
"No download Process"
NSString *path = @ "";
Nsurl *url = [Nsurl Urlwithstring:path];
Nsurlsession *session = [Nsurlsession sharedsession];
Nsmutableurlrequest *request = [Nsmutableurlrequest Requestwithurl:url];
Nsurlsessiondownloadtask *task = [Session downloadtaskwithrequest:request completionhandler:^ (NSURL * _Nullable Location, Nsurlresponse * _nullable response, Nserror * _nullable error) {
Nsfilemanager *FM = [Nsfilemanager Defaultmanager];
[FM moveitematurl:location tourl:[nsurl fileurlwithpath:@ "/users/nil/desktop/song.mp3"] error:nil];
}];
[Task resume];
"There is a download process"
NSString *path = @ "";
Nsurl *url = [Nsurl Urlwithstring:path];
Nsmutableurlrequest *request = [Nsmutableurlrequest Requestwithurl:url];
Nsurlsessionconfiguration *config = [Nsurlsessionconfiguration defaultsessionconfiguration];
Nsurlsession *session = [nsurlsession sessionwithconfiguration:config delegate:self DelegateQueue:[NSOperationQueue Mainqueue]];
Nsurlsessiondownloadtask *task = [session downloadtaskwithrequest:request];
[Task resume];
-(void) Urlsession: (Nsurlsession *) session Downloadtask: (Nsurlsessiondownloadtask *) Downloadtask Didwritedata: ( int64_t) Byteswritten Totalbyteswritten: (int64_t) Totalbyteswritten totalbytesexpectedtowrite: (int64_t) totalbytesexpectedtowrite{
Size per part, total size, current downloaded size
NSLog (@ "%LLD---%lld---%lld", byteswritten,totalbytesexpectedtowrite,totalbyteswritten);
self.myPV.progress = Totalbyteswritten*1.0/totalbytesexpectedtowrite;
}
-(void) Urlsession: (Nsurlsession *) session Downloadtask: (Nsurlsessiondownloadtask *) downloadtask
Didfinishdownloadingtourl: (Nsurl *) location{
Nsfilemanager *FM = [Nsfilemanager Defaultmanager];
[FM moveitematurl:location tourl:[nsurl fileurlwithpath:@ "/users/nil/desktop/haha.mp3"] error:nil];
}
Lan Yi Education Session Download