【问题标题】:ASIHTTPRequest for download documents fail second timeASIHTTPRequest 下载文件第二次失败
【发布时间】:2012-09-06 10:04:08
【问题描述】:

我正在使用 ASIHTTP 从服务器下载一些文档。我有一个按钮,它首先控制本地版本(保存在 iPad 文件系统上)和服务器版本之间的差异,然后(在确认警报视图之后)开始下载。 要下载我使用此代码的文档:

for (SyncNode *node in _syncDocuments) {
        //SyncNode is a my Class that handle document
        // start the download
        NSString *filename = [NSString stringWithFormat:@"%@.%@",node.uniqueIdentifier,node.extension];
        NSString *tempPath = [SavedDocument pathToSyncFile:filename];
        // tempPath is a string like this
        // /var/mobile/Applications/5C05AA6F-55B3-46FD-8330-094BD0E61973/Documents/SyncDocumentsFolder/D49B421C-7528-4A3D-A8F6-942FF03881D0/f2e650e2-cff7-4485-9152-5445bee436f2.jpg

        //BaseHTTPRequest is an extension of ASIHTTPRequest
        BaseHTTPRequest *request = [[[BaseHTTPRequest alloc] initWithURL:[NSURL URLWithString:node.contentLocation] accountUUID:_uuid] autorelease];
        request.userInfo = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:i+1] forKey:@"requestNumber"];
        [request setDelegate:self];
        [request setShowAccurateProgress:YES];
        [request setDownloadProgressDelegate:self];
        [request setDownloadDestinationPath:tempPath];

        [request startAsynchronous];
}

情景。

  1. 我没有在 iPad 上存储任何本地文件
  2. 我按下按钮,例程计算下载大小
  3. 我接受下载并且例行程序会下载所有文档。当我尝试显示其中一个文档(在 Web 视图中)时,它工作正常,我可以看到该文档。
  4. 我删除了所有本地文档(删除过程完美,实际上文档存在于文件系统中)。

现在,我处于与 1 相同的情况。但是当我尝试再次(第二次)下载相同的文档时,所有 ASIHTTPRequest 都会在很短的时间间隔内返回并调用我的 - (void)requestFinished:(ASIHTTPRequest *)request 方法。 示例:我有一个包含 8MB 文档的目录;第一次例程需要 11 或 12 秒才能完成所有下载。而是第二次使用相同的例程,使用相同的文档需要不到 1 秒的时间来完成所有下载。

好像下载没有运行,但是ASIHTTP没有调用任何错误委托方法。

当我尝试显示下载的文档(第二次)时,我在控制台中看到以下错误消息:

   Error copying file to temp path Error Domain=NSCocoaErrorDomain Code=260 "The operation
 couldn’t be completed. (Cocoa error 260.)" UserInfo=0x1229e900 
{NSFilePath=/var/mobile/Applications/5C05AA6F-55B3-46FD-8330-
094BD0E61973/Documents/SyncDocumentsFolder/D49B421C-7528-4A3D-A8F6-942FF03881D0/f2e650e2-cff7-
4485-9152-5445bee436f2.jpg, NSUnderlyingError=0x1229e570 "The operation couldn’t be completed. 
No such file or directory"}

这个问题把我逼疯了! 有什么想法吗?

【问题讨论】:

    标签: iphone ios ipad asihttprequest


    【解决方案1】:

    尝试使用setCachePolicypropery 为您的请求设置缓存策略。

    [request setCachePolicy:(ASIDoNotReadFromCacheCachePolicy | ASIDoNotWriteToCacheCachePolicy)];
    

    更多信息请阅读:http://allseeing-i.com/ASIHTTPRequest/How-to-use#using_a_download_cache

    【讨论】:

    • 谢谢!你是我的新偶像!我已经尝试过使用这个属性,但也许我设置了错误的值!
    猜你喜欢
    • 2022-08-15
    • 2016-08-25
    • 1970-01-01
    • 2013-12-17
    • 2020-10-02
    • 2011-03-22
    • 1970-01-01
    • 2012-04-10
    • 2015-09-01
    相关资源
    最近更新 更多