iphone - 使用 ASIHTTPRequest 库从服务器下载视频文件(MB 大小)

标签 iphone download asihttprequest

在我的应用程序中,我想从服务器下载视频文件并将该文件存储在 iPhone 文档目录中。

对于下载,我使用 ASIHTTPRequest 库,并且我已经下载了视频(以 KB 大小)并存储到文档目录中。

但是,当我下载视频(以 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];
 }

此文件(Movie.m4v)大小为 2.2 MB,当我从服务器下载此视频时,意味着没有下载任何视频。

请建议我如何使用 ASIHTTPRequest 从服务器下载视频文件(MB 大小)?

我正在使用 XCode 4.2 和 iOS 5 sdk。

如果有任何示例代码意味着它对我非常有帮助。

谢谢!!!

最佳答案

 -(void)viewDidLoad 

{

    [super viewDidLoad];

     NSURL *url = [NSURL URLWithString:@"http://mobile.aghaven.com/Downloads/video/Movie.m4v"];

     ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
     [request setDownloadDestinationPath:@"/Users/pk/Desktop/my_file.m4v"];
     [request setDelegate:self];
     [request startAsynchronous];

}

 -(void)requestFinished:(ASIHTTPRequest *)request

{

    [[[[UIAlertView alloc] initWithTitle:@"Message" 
                                 message:@"Success!!!" 
                                delegate:self 
                       cancelButtonTitle:@"OK" 
                       otherButtonTitles:nil] autorelease] show];

}

 -(void)requestFailed:(ASIHTTPRequest *)request
{

    NSLog(@"%@",request.error);

}

您将看到该文件位于桌面上。

享受吧!

关于iphone - 使用 ASIHTTPRequest 库从服务器下载视频文件(MB 大小),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8635491/

相关文章:

iphone - 如何将核心数据添加到现有项目中?

iphone - 如何在没有新版本的情况下更新应用程序商店中的应用程序?

cocoa-touch - 在 ASINetworkQueue 中使用 UIProgressView 为 ASIHTTPRequest 显示准确的进度

objective-c - NSOperation 中的 ASINetworkQueue 阻塞主线程

iphone - 卡在沙盒帐户中

iphone - 删除 NSURL : iOS 的最后部分

Apache2 服务器 MIME 类型

r - 隐藏最终链接时,下载一个保留原始文件名的文件

grails - 在内存中创建文件并让用户下载

ios - ASIHTTPRequest 获取请求 - 未调用委托(delegate)