Estoy tratando de implementar la lógica de reintento con retroceso exponencial usando NSTimer. Mi código es el siguiente:Uso de NSTimer para implementar la lógica de reintento con retroceso exponencial
-(void)start
{
[NSTimer scheduledTimerWithTimeInterval:0.0 target:self
selector:@selector(startWithTimer:) userInfo:nil repeats:NO];
}
-(void)startWithTimer:(NSTimer *)timer
{
if (!data.ready) {
// timer.timeInterval == 0.0 ALWAYS!
NSTimeInterval newInterval = timer.timeInterval >= 0.1 ? timer.timeInterval * 2 : 0.1;
newInterval = MIN(60.0, newInterval);
NSLog(@"Data provider not ready. Will try again in %f seconds.", newInterval);
NSTimer * startTimer = [NSTimer scheduledTimerWithTimeInterval:newInterval target:self
selector:@selector(startWithTimer:) userInfo:nil repeats:NO];
// startTimer.timeInteval == 0.0 ALWAYS!
return;
}
...
}
El problema que estoy teniendo es que el temporizador NSTimer scheduledTimerWithTimeInterval parece ignorar el intervalo que estoy proporcionando y siempre lo establece en 0,0. ¿Alguna sugerencia sobre lo que estoy haciendo mal aquí?
¡Gracias! Creo que debería leer los documentos la próxima vez. :) – Ivan