use*_*136 2 iphone download asihttprequest
在我的应用程序中,我想从服务器下载视频文件并将该文件存储在IPhone文档目录中.
为了下载我正在使用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];
}
Run Code Online (Sandbox Code Playgroud)
此文件(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);
}
Run Code Online (Sandbox Code Playgroud)
你会看到该文件在桌面上.
请享用!
| 归档时间: |
|
| 查看次数: |
4687 次 |
| 最近记录: |