我正在使用 ASI 下载文件,并且一直看到ASIFileManagementError
. 我猜这意味着我为我的请求构建下载路径的方式有问题,但并不一致。有时下载工作得很好,有时它会失败。即使在同一设备上使用相同的代码下载相同的文件!这是我的代码。
-(ASIHTTPRequest*)buildDownloadLinkForUpdate:(ContentItem*)update
{
NSString *URLString = [[NSString alloc] initWithFormat:@"%@?%@=%@", update.downloadUrl.absoluteString, @"auth_token", database.userAuthToken];
NSURL *url = [NSURL URLWithString:URLString];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setRequestMethod:@"GET"];
ContentItem* item = [database getItemWithId:update.uniqueId];
[request setDownloadDestinationPath:item.contentPath];
[request setTemporaryFileDownloadPath:[[AppSettings instance].temporaryPath stringByAppendingPathComponent:item.fileName]];
[request setAllowResumeForFileDownloads:TRUE];
[request setShowAccurateProgress: TRUE];
[request setDelegate:[_currentItem progressDelegate]];
return request;
}
-(void)initalizeNetworkQueue
{
if(!networkQueue) networkQueue = [[ASINetworkQueue alloc] init];
[networkQueue cancelAllOperations];
[networkQueue reset];
if([_currentItem progressDelegate])
{
[networkQueue setDownloadProgressDelegate:[_currentItem progressDelegate]];
}
[networkQueue setDelegate:self];
[networkQueue setRequestDidFinishSelector:@selector(networkQueueComplete:)];
[networkQueue setRequestDidFailSelector:@selector(networkQueueFailed:)];
[networkQueue setShowAccurateProgress:YES];
networkQueue.maxConcurrentOperationCount = 1;
}
然后这里是实际调用它的代码:
[self initalizeNetworkQueue];
[networkQueue addOperation:[self buildDownloadLinkForUpdate:_currentUpdate]];
[networkQueue go];
currentState = ContentUpdaterStateDownloading;
这里有什么明显的错误吗?
-= UPDATE=- 表示它失败了,因为它无法将文件从临时位置移动到最终位置。
Download Failed: Failed to move file from '/var/mobile/Applications/33E1DF3C-17F5-432F-8204-A9B53AB5AAE3/Documents/.temp/FileShare+Gate+4.pptx' to '/var/mobile/Applications/33E1DF3C-17F5-432F-8204-A9B53AB5AAE3/Documents/.content/FileShare+Gate+4.pptx'