0

我正在从网上下载一个文件。当我恢复文件的下载时,它会从起点重新启动,而不是从我暂停下载的点重新启动。我在暂停下载时保存了下载文件的值。但现在我无法恢复我暂停的文件的下载。我正在使用此代码下载新文件

      url = [NSURL URLWithString:_item.link];   
    _receivedBytes = 0;
    _speed = 0;
    _lastTime = [[NSDate date] timeIntervalSince1970];
    _connection = [ASIWebPageRequest requestWithURL:url];
    [_connection setUrlReplacementMode:ASIReplaceExternalResourcesWithData];
    [_connection setDelegate: self];
    [_connection setDownloadProgressDelegate:self];
    [_connection setDownloadCache:[ASIDownloadCache sharedCache]];
    [_connection setDownloadDestinationPath: _item.path];
    [_connection startAsynchronous];
4

1 回答 1

0

根据 ASIHTTPRequest 文档,仅当您直接下载到文件中时,才能恢复中断的下载。

我假设您下载到内存中(因为您正在使用_receivedBytes)。

如果您将下载的文件存储到设备文件系统中,您可以使用以下命令将其直接下载到文件系统中:

ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setTemporaryFileDownloadPath:@"/path/to/tempfolder/yourfile.jpg.download"];
[request setDownloadDestinationPath:@"/path/to/final/destination/yourfile.jpg"];

然后,您可以通过设置启用中断下载的恢复:

[request setAllowResumeForFileDownloads:YES];

您将在此处找到更多详细信息

于 2012-08-02T08:44:26.017 回答