2

我正在使用 ASIHTTPRequest 从服务器下载文件,但它给出错误

无法将文件从“/Users/admin/Library/Application Support/iPhone Simulator/3.1.3/Applications/8650FFE4-9C18-425C-9CEE-7392FD788E6D/Documents/temp/test.zip.download”移动到“/Users/” admin/Library/Application Support/iPhone Simulator/3.1.3/Applications/8650FFE4-9C18-425C-9CEE-7392FD788E6D/Documents/test.zip'

任何人都可以告诉mw这个错误我的代码有什么问题......

    NSURL *url = [NSURL URLWithString:@"http://wordpress.org/latest.zip"];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setDelegate:self];

NSArray *dirArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,    NSUserDomainMask, YES);

NSString *path = [NSString stringWithFormat:@"%@/test.zip", [dirArray objectAtIndex:0]];

//NSString *tempPath = [NSString stringWithFormat:@"%@test.zip", NSTemporaryDirectory()]    ;

NSString *tempPath =[NSString stringWithFormat:@"%@/temp/test.zip.download", [dirArray objectAtIndex:0]];

// The full file will be moved here if and when the request completes successfully
[request setDownloadDestinationPath:path];
[request setTemporaryFileDownloadPath:tempPath];
[request setDidFinishSelector:@selector(requestDone:)];
[request setDidFailSelector:@selector(requestWentWrong:)];
[[self queue] addOperation:request]; //queue is an NSOperationQueue
4

3 回答 3

1

你在那个位置已经有一个 temp.zip 了吗?

于 2010-05-18T12:41:35.793 回答
0

如果您没有正确设置目标路径,也会发生这种情况,使用这种setDownloadDestinationPath:方法ASIHTTPRequest...

于 2011-06-29T11:24:13.390 回答
0

您的调用 [request setTemporaryFileDownloadPath:tempPath]; 不是必需的,并且很可能是您的错误的根源。

于 2015-08-06T05:21:28.223 回答