AFNetworking + big download files + resume downloads

前端 未结 2 1277
攒了一身酷
攒了一身酷 2021-02-03 14:36

I need to download files > 500 Mo with AFNetworking. Sometimes, the time to download them is > 10 minutes and if the app is in background, the download can\'t be complete.

相关标签:
2条回答
  • 2021-02-03 15:01

    I ended up using the old (non ARC) ASIHTTPRequest framework for a similar task. AllowResumeForFileDownloads does what you need. Note that you server needs to support resuming by reading the Range http header.

    if (![[NSFileManager defaultManager] fileExistsAtPath:downloadPath]){
        ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
        [request setDelegate:self];
        [request setAllowResumeForFileDownloads:YES];
        [request setDownloadDestinationPath:downloadPath];
        [request setTemporaryFileDownloadPath:tmpPath];
        [request startAsynchronous];
    }
    
    0 讨论(0)
  • 2021-02-03 15:26

    Update:

    As steipete may wont maintain AFDownloadRequestOperation any more (https://github.com/steipete/AFDownloadRequestOperation/pull/68). NSURLSessionDownloadTask may be a better choice.


    https://github.com/steipete/AFDownloadRequestOperation

    Also, I write a lib base on AFDownloadRequestOperation: https://github.com/BB9z/RFDownloadManager

    0 讨论(0)
提交回复
热议问题