在我的应用程序中,我想从服务器下载视频文件并将该文件存储在IPhone文档目录中。使用ASIHTTPRequest库从服务器下载视频文件(以MB为单位)
对于下载,我使用ASIHTTPRequest库,我已经下载了视频(KB大小)并存储到Document目录中。
但是,当我下载视频(MB大小)意味着,该请求需要更多的时间来下载视频,并没有结果(我一直在等待15分钟以上,但没有下载)。
我已经尝试了下面的代码在我的应用程序,这是从服务器单一下载。
- (IBAction)grabURLInBackground:(id)sender
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSURL *url = [NSURL URLWithString:@"http://mobile.aghaven.com/Downloads/video/Movie.m4v"];
//NSString *file = [NSString stringWithFormat:@"%@/movie.mov", documentsDirectory];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
NSString* file = [documentsDirectory stringByAppendingPathComponent:@"Movie.m4v"];
[request setDelegate:self];
[request setTimeOutSeconds:60];
[request setNumberOfTimesToRetryOnTimeout:2];
[request setDownloadDestinationPath:file];
[request startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
[[[[UIAlertView alloc] initWithTitle:@"Message"
message:@"Success!!!"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil] autorelease] show];
}
这个文件中有2.2 MB大小,当我下载从服务器表示这部影片(Movie.m4v),没有视频下载。
请建议我如何使用ASIHTTPRequest?从服务器下载视频文件(以MB为单位)。
我正在使用iOS 5 sdk的XCode 4.2。
如果有示例代码对我非常有帮助。
谢谢!
尝试使用进度var来检查它何时停止下载。只是为了测试目的注释掉设置的超时时间,然后再试一次。加上尝试下载超过2 MB的图像... – doNotCheckMyBlog 2011-12-26 12:08:41
只需要注意,ASI不再被维护。您应该尝试使用AFNetworking。 – 2011-12-26 12:53:42
很多谢谢dontCheckMyBlog,雅各布Relkin ..我会考虑你的建议.. – user2136 2011-12-27 02:45:39