iOS 9: se llama a beginBackgroundTaskWithExpirationHandler antes del tiempo de espera
Estoy trabajando en llamadas VOIP y agregando soporte a iOS <10. Para llamadas VOIP entrantes cuando la aplicación está en segundo plano, estoy usando UILocalNotification (en desuso en iOS 10).
Para hacer una llamada 60 segundos (o 1 minuto) estoy usando este código
count = 0;
apnTimer = [NSTimer scheduledTimerWithTimeInterval:3.0
target:self
selector:@selector(showIncomingCall:)
userInfo:userInfo
repeats:YES];
self.backgroundTask = [application beginBackgroundTaskWithExpirationHandler:^{
NSLog(@"ALVOIP : BACKGROUND_HANDLER_NO_MORE_TASK_RUNNING.");
[application endBackgroundTask:self.backgroundTask];
self.backgroundTask = UIBackgroundTaskInvalid;
}];
-(void)showIncomingCall:(NSTimer *)timer
{
if (count < 60)
{
UIApplication *application = [UIApplication sharedApplication];
[application presentLocalNotificationNow:localNotification];
NSLog(@"Time Remaining: %f", [[UIApplication sharedApplication] backgroundTimeRemaining]);
count = count + 3;
return;
}
// TIMEOUT : STOP TIMER AND LOCAL NOTIFICATION BACKGROUND TASK
[self invalidateCallNotifying];
}
-(void)invalidateCallNotifying
{
[apnTimer invalidate];
if (self.backgroundTask != UIBackgroundTaskInvalid)
{
[[UIApplication sharedApplication] endBackgroundTask:self.backgroundTask];
self.backgroundTask = UIBackgroundTaskInvalid;
}
}
para extender el tiempo de proceso en segundo plano a 1 minuto y funciona en iOS 10.1.1 (iPhone) pero no funciona en iOS 9.3.5 (iPad). De alguna manera, el controlador está invocando 30-33 segundos?
ACTUALIZAR:
Traté de comentar este código:
self.backgroundTask = [application beginBackgroundTaskWithExpirationHandler:^{
NSLog(@"ALVOIP : BACKGROUND_HANDLER_NO_MORE_TASK_RUNNING.");
[application endBackgroundTask:self.backgroundTask];
self.backgroundTask = UIBackgroundTaskInvalid;
}];
Aún así puedo hacer 30-33 segundos, es decir, no sé por qué esto no funciona.