Tôi cần tải xuống tệp> 500 Mo với AFNetworking. Đôi khi, thời gian tải xuống là> 10 phút và nếu ứng dụng ở chế độ nền, quá trình tải xuống không thể hoàn tất.AFNetworking + tệp tải xuống lớn + tiếp tục tải xuống
Vì vậy, tôi muốn thử tải xuống một phần. Tôi tìm thấy rất nhiều liên kết và điều này có vẻ là có thể với phương thức pause() và resume() trên AFHTTPRequestOperation.
Thực ra, tôi đã làm:
[self.downloadOperation setShouldExecuteAsBackgroundTaskWithExpirationHandler:^{
// Clean up anything that needs to be handled if the request times out
[self.downloadOperation pauseDownload];
}];
DownloadOperation là một lớp con của AFHTTPRequestOperation (singleton).
Và trong appdelegate:
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// resume will only resume if it's paused...
[[DownloadHTTPRequestOperation sharedOperation] resumeDownload];
}
Máy chủ là OK để có được những dòng sản phẩm mới trong tiêu đề ...
Câu hỏi của tôi:
1) Là-t cách tốt để làm nó? 2) Tiếp tục có cần thay đổi outputStream (chắp thêm: NO => chắp thêm: YES) không? Hay nó được quản lý ở đâu đó bằng AFNetworking? (Không tìm thấy)
self.outputStream = [NSOutputStream outputStreamToFileAtPath:self.filePath append:YES];
Something như thế này (trong DownloadHTTPRequestOperation):
- (void)pauseDownload
{
NSLog(@"pause download");
[self pause];
}
- (void)resumeDownload
{
NSLog(@"resume download");
self.outputStream = [NSOutputStream outputStreamToFileAtPath:self.filePath append:YES];
[self resume];
}
Nhờ sự giúp đỡ của bạn.
BTW AFNetworking cũng là "phi ARC" – pahan
AFNetworking là ARC kích hoạt ngay bây giờ. – tangqiaoboy