iOS 9: beginBackgroundTaskWithExpirationHandler está sendo chamado antes do tempo limite
estou trabalhando na chamada VOIP e adicionando suporte ao iOS <10. Para chamadas VOIP recebidas quando o aplicativo está em segundo plano, estou usando o UILocalNotification (descontinuado no iOS 10).
Para fazer uma ligação 60 segundos (ou 1 minuto), estou 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 estender o tempo do processo em segundo plano para 1 minuto e está funcionando no iOS 10.1.1 (iPhone), mas não no iOS 9.3.5 (iPad). De alguma forma manipulador está invocando 30-33 segundos?
ATUALIZAR:
Eu tentei comentar este código:
self.backgroundTask = [application beginBackgroundTaskWithExpirationHandler:^{
NSLog(@"ALVOIP : BACKGROUND_HANDLER_NO_MORE_TASK_RUNNING.");
[application endBackgroundTask:self.backgroundTask];
self.backgroundTask = UIBackgroundTaskInvalid;
}];
Ainda sou capaz de fazer de 30 a 33 segundos, ou seja, não sei por que isso não está funcionando?