6
Tôi cần tải xuống các tệp .zip lớn (tối đa 800 MB) bằng ứng dụng iPad của mình. Tôi muốn tiếp tục tải xuống lại nếu nó bị hủy hoặc nếu ứng dụng ở chế độ nền.AFNetworking + Pause/Tiếp tục tải xuống các tệp lớn
operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:filePath append:YES];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject){
// unzip the .zip
}failure:^(AFHTTPRequestOperation *operation, NSError *error){
//Handle the error
}];
[operation setDownloadProgressBlock:^(NSInteger bytesWritten, long long totalBytesWritten,long long totalBytesExpectedToWrite) {
//update the progressView
}];
[operation setShouldExecuteAsBackgroundTaskWithExpirationHandler:^{
// What I have to do here?
}];
[operation start];
[operation waitUntilFinished];
-(void)applicationWillResignActive:(UIApplication *)application{
// What I have to do here?
}
Cảm ơn sự giúp đỡ của bạn.
Có phương án không ARC nào khác không? – Tudorizer
Bạn có biết điều này có hoạt động với chuyển hướng URL không? Tôi đã đặt url rồi chuyển hướng đến tệp thực để tải xuống. Tải xuống dường như không tiếp tục sử dụng các URL này. –
Chỉ cần đảm bảo rằng bạn chỉ định cùng một targetPath mỗi lần. Ngoài ra nó không thể là thư mục; nếu bạn chỉ định một thư mục, nó sẽ sử dụng URL để đặt tên cho tệp. – mrgrieves