AFNetworking + big download files + resume downloads

前端 未结 2 1279
攒了一身酷
攒了一身酷 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];
    }
    

提交回复
热议问题