我正在使用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'
答案 0 :(得分:0)
之前我遇到过此错误,它处于连接状态,类型为ASINetworkErrorType
,表示无法访问主机。
无论如何ASIHttprequest
现在已经死了,你找不到很多问题的答案,接受我的建议并选择AFNetworking,这很棒并且可以胜任。