Tôi đang sử dụng mã này để lặp qua một mảng để tải xuống nhiều tệp và ghi vào đĩa.AFnetworking tải xuống nhiều tệp
-(void)download
{
//set url paths
for (NSString *filename in syncArray)
{
NSString *urlpath = [NSString stringWithFormat:@"http://foo.bar/photos/%@", filename];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlpath]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:filename];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Successfully downloaded file to %@", path);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
[operation start];
nhưng vấn đề là nó gọi là khối thành công sau mỗi tập tin được thực hiện, (mà nó nên) nhưng tôi chỉ cần một cuộc gọi cuối cùng lại để tải lại một số dữ liệu và kết thúc một tiến bộ HUD.
Bất kỳ con trỏ nào đi đúng hướng đều tuyệt vời.
Hey, Bạn gọi hàm này ở đâu? Trong AppDelegate hoặc trong một bộ điều khiển cụ thể? Ngoài ra, điều gì sẽ xảy ra nếu ứng dụng bị thoát trước khi quá trình tải xuống hoàn tất? Cảm ơn – manishKungwani