i'm working on VOIP call and adding support to iOS < 10. For incoming VOIP call when app is in background, i'm using UILocalNotification (deprecated in iOS 10).
To make a call 60 secs (or 1 minute) i'm using this code
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;
}
}
to extend background process time to 1 minute and it's working in iOS 10.1.1 (iPhone) but not working in iOS 9.3.5 (iPad). Somehow handler is invoking 30-33 secs?
UPDATE:
i tried to comment this code :
self.backgroundTask = [application beginBackgroundTaskWithExpirationHandler:^{
NSLog(@"ALVOIP : BACKGROUND_HANDLER_NO_MORE_TASK_RUNNING.");
[application endBackgroundTask:self.backgroundTask];
self.backgroundTask = UIBackgroundTaskInvalid;
}];
Still i'm able to do 30-33 secs i.e i don't know why this is not working?