1

我正在做一个项目,我需要为服务器下载 3 个不同的 .plist 文件,但我只能下载其中一个。谁知道怎么把这三个都下载下来?我正在使用 ASIHTTPRequest。我的代码:

- (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];

}

我想我在正确的轨道上,但不确定......干杯!

4

1 回答 1

3

您在多个地方使用了相同的变量名来获取三个文件。第一个变量是“filePath”

将变量更改为单独的名称,例如这样,

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

“请求”变量也是如此?

像这样进行更正,

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

或者,如果您只想拥有 1 个请求对象,则可以尝试遍历所有 3 个 url 并一一分配请求。确保在循环中提供不同的文件路径

[request setDownloadDestinationPath:filePath**{N}**];
于 2012-11-05T14:57:44.677 回答