简体   繁体   English

使用ASIHTTPRequest下载多个文件

[英]Downloading multiple files with ASIHTTPRequest

I'm working on a project where I need to have 3 different .plist files downloaded for a server but I only manage to get one of them downloaded. 我正在开发一个项目,我需要为服务器下载3个不同的.plist文件,但我只设法下载其中一个。 Anyone know how to get all 3 of them downloaded? 有谁知道如何下载所有3个? I'm using ASIHTTPRequest. 我正在使用ASIHTTPRequest。 Mycode: mycode的:

- (void)downloadPlist {
NSLog(@"Download in progress...");


progressView.alpha = 1.0;


// Here we're downloading the .plist file from a server to the app's Documents Directory.
// Create file manager
fileManager = [NSFileManager defaultManager];

// Point to Document directory
documentsDirectory = [NSHomeDirectory()
                      stringByAppendingPathComponent:@"Documents"];


documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];

filePath = [documentsDirectory stringByAppendingPathComponent:@"example1.plist"];
filePath = [documentsDirectory stringByAppendingPathComponent:@"example2.plist"];
filePath = [documentsDirectory stringByAppendingPathComponent:@"example3.plist"];




// files from server.
NSURL *url = [NSURL URLWithString:@"http://myWeb.com/example1.plist"];
NSURL *url1 = [NSURL URLWithString:@"http://myWeb.com/example2.plist"];
NSURL *url2 = [NSURL URLWithString:@"http://myWeb.com/example3.plist"];



request = [ASIHTTPRequest requestWithURL:url];
request = [ASIHTTPRequest requestWithURL:url1];
request = [ASIHTTPRequest requestWithURL:url2];
[request setShowAccurateProgress:YES];
[request setDownloadDestinationPath:filePath];
[request setDownloadProgressDelegate:progressView];
[request setDelegate:self];
[request startAsynchronous];

} }

I think I'm on the right track but not sure... cheers! 我想我走在正确的轨道但不确定......干杯!

You have used same variable names in several places to get three files. 您已在多个位置使用相同的变量名来获取三个文件。 First variable is "filePath" 第一个变量是“filePath”

Change the variables to separate names for eg like this, 将变量更改为单独的名称,例如,

filePath1 = [documentsDirectory stringByAppendingPathComponent:@"example1.plist"];
filePath2 = [documentsDirectory stringByAppendingPathComponent:@"example2.plist"];
filePath3 = [documentsDirectory stringByAppendingPathComponent:@"example3.plist"];

Same is with "request" variable?? 与“请求”变量相同?

Make correction for eg like this, 像这样进行修正,

request1 = [ASIHTTPRequest requestWithURL:url];
request2 = [ASIHTTPRequest requestWithURL:url1];
request3 = [ASIHTTPRequest requestWithURL:url2];

Or if you want to have only 1 request object then maybe try loop over all 3 urls and assign request one by one. 或者,如果您只想拥有1个请求对象,则可以尝试遍历所有3个URL并逐个分配请求。 Make sure you supply different filePaths in your loop 确保在循环中提供不同的filePath

[request setDownloadDestinationPath:filePath**{N}**];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM