Necesito descargar archivos> 500 Mo con AFNetworking. A veces, el tiempo para descargarlos es> 10 minutos y si la aplicación está en segundo plano, la descarga no puede completarse.AFNetworking + grandes archivos de descarga + reanudar descargas
Así que quiero intentar descargas parciales. Encontré muchos enlaces y esto parece ser posible con los métodos pause() y resume() en AFHTTPRequestOperation.
En realidad, lo hice:
[self.downloadOperation setShouldExecuteAsBackgroundTaskWithExpirationHandler:^{
// Clean up anything that needs to be handled if the request times out
[self.downloadOperation pauseDownload];
}];
DownloadOperation es una subclase de AFHTTPRequestOperation (Singleton).
Y en AppDelegate:
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// resume will only resume if it's paused...
[[DownloadHTTPRequestOperation sharedOperation] resumeDownload];
}
El servidor está bien obtener la nueva gama de cabeceras ...
Mis preguntas:
1) es-t la buena manera de hacerlo eso ? 2) ¿El currículum necesita cambiar el outputStream (anexar: NO => append: YES)? ¿O lo está gestionado en algún lugar por AFNetworking? (No se encuentra)
self.outputStream = [NSOutputStream outputStreamToFileAtPath:self.filePath append:YES];
Algo como esto (en DownloadHTTPRequestOperation):
- (void)pauseDownload
{
NSLog(@"pause download");
[self pause];
}
- (void)resumeDownload
{
NSLog(@"resume download");
self.outputStream = [NSOutputStream outputStreamToFileAtPath:self.filePath append:YES];
[self resume];
}
Gracias por su ayuda.
Por cierto AFNetworking es también "no ARC" – pahan
AFNetworking es ARC habilitado ahora. – tangqiaoboy