Lan Yi Education Session Download

Source: Internet
Author: User

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

Related Article

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.