【发布时间】:2013-01-25 11:04:41
【问题描述】:
我正面临这个奇怪的问题。在点击一个按钮时,我正在从我的 PHP 服务器下载媒体文件,例如图像、视频和音频。对于下载部分,我使用ASIHTTPRequest。
我使用此代码恢复下载:
NSString *audio_url_f = [myDetailPeom poem_audio_url];
NSURL *url = [NSURL URLWithString:audio_url_f];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request setShouldContinueWhenAppEntersBackground:YES];
[request setNumberOfTimesToRetryOnTimeout:3];
[request setDelegate:self];
//
NSString *path = [NSString stringWithFormat:@"%@/Documents/%@",NSHomeDirectory(),fileName];
path = [path stringByAppendingString:@".download"];
// This file has part of the download in it already
[request setTemporaryFileDownloadPath:path];
[request setAllowResumeForFileDownloads:YES];
[request setDownloadDestinationPath:filePath];
//
[request setUserInfo:[NSDictionary dictionaryWithObject:@"audio" forKey:@"type"]];
[request setDidFinishSelector:@selector(requestFinished:)];
[request setDidFailSelector:@selector(requestFailed:)];
[request startAsynchronous];
如果网络出现故障,下载将停止并正常恢复。部分下载的文件是在正确的位置创建的,文件名中附加了.download。一旦网络可用,它会正常恢复下载。
现在我将我的 Web 应用程序移至实时 PHP 服务器(两者都在同一台服务器上)。但部分文件根本没有创建。
【问题讨论】:
-
不考虑您的问题,但考虑切换到其他框架,例如
AFNetworking。ASIHTTP不再由作者维护/支持
标签: iphone ios ios4 asihttprequest