I’m using ASIHTTP for download some documents from a server. I have a button that first control the differences between the local version (saved on iPad file system) and the server version and then (after a confirm alert view) starts the downloads.
To download the documents I use this code:
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];
}
Scenario.
- I don’t have any local file stored on iPad
- I push the button and the routine calculate the size of the download
- I accept the download and a routine dowloads all documents. When I try to display one of this documents (in a web view) it works fine and I can see the document.
- I delete all local documents (the delete process works perfectly, in fact the documents exists on the file system).
Now, I’am in the same situation of 1. but when I try to dowload the same documents again (the second time) all ASIHTTPRequest return and call my - (void)requestFinished:(ASIHTTPRequest *)request method, in a very short time interval.
Example: I have a directory with 8MB of documents; the first time the routine needs 11 or 12 seconds to complete all download. Instead the second time the same routine, with the same documents needs less than 1 second to complete all downloads.
It’s seem that the download not run, but ASIHTTP doesn’t call any error delegate methods.
When I try to show a document downloaded (the second time) I see this error message in the console:
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"}
This problem drive me crazy !
Any ideas ?
Try to set a cache policy for your request using
setCachePolicypropery.For more informations read this: http://allseeing-i.com/ASIHTTPRequest/How-to-use#using_a_download_cache