Nsurlsession implementation Download (Cannot see download progress)

Source: Internet
Author: User

Nsurlsession implementation Download (Cannot see download progress)

/**

 * Download task: Cannot see download progress
*/
- (void) Downloadtask
{
//1.GetSessionObject
nsurlsession *session = [nsurlsessionsharedsession];

//2.Create a downloadTask
Nsurl *url = [Nsurlurlwithstring:@ "Http://localhost:8080/MJServer/resources/test.mp4"];
Nsurlsessiondownloadtask *task = [Session Downloadtaskwithurl: URLCompletionhandler:^(Nsurl*location, Nsurlresponse *response,Nserror *error) {
//Location: path to temporary files (downloaded files)

NSString *caches = [Nssearchpathfordirectoriesindomains(nscachesdirectory,Nsuserdomainmask,YES) Lastobject];
//Response.suggestedfilename : recommended file name, generally consistent with the server-side file name
NSString *file = [Cachesstringbyappendingpathcomponent: Response.Suggestedfilename];

// cut or copy a temporary fileCachesfolder
Nsfilemanager *mgr = [NsfilemanagerDefaultmanager];

//Atpath: file path before clipping
//Topath: the file path after clipping
[Mgr Moveitematpath: Location.PathTopath: FileError:Nil];
}];

//3.Start Task
[Task Resume];
}
Note: nsurlsessiondownloadtask After the download is complete, save the data in the TMP temp file in the sandbox, you need to cut or copy the temporary files Caches Folder.

Nsurlsession implementation Download (Cannot see download progress)

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.