From d9c51e485456d3b81ce18565d2b2590345268f7e Mon Sep 17 00:00:00 2001 From: Guillaume BIENKOWSKI Date: Thu, 10 Jul 2014 14:28:02 +0200 Subject: [PATCH] Use named background task when possible --- Classes/LinphoneManager.m | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 24eeab399..0df79656e 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -629,11 +629,19 @@ static void linphone_iphone_display_status(struct _LinphoneCore * lc, const char [[UIApplication sharedApplication] presentLocalNotificationNow:data->notification]; if (!incallBgTask){ - incallBgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler: ^{ - [LinphoneLogger log:LinphoneLoggerWarning format:@"Call cannot ring any more, too late"]; - [[UIApplication sharedApplication] endBackgroundTask:incallBgTask]; - incallBgTask=0; - }]; + UIApplication* app = [UIApplication sharedApplication]; + + void (^expirationHandler)() = ^{ + [LinphoneLogger log:LinphoneLoggerWarning format:@"Call cannot ring any more, too late"]; + [[UIApplication sharedApplication] endBackgroundTask:incallBgTask]; + incallBgTask=0; + }; + + if( [app respondsToSelector:@selector(beginBackgroundTaskWithName:expirationHandler:)] ){ + incallBgTask = [app beginBackgroundTaskWithName:@"Linphone in-call bg task" expirationHandler:expirationHandler]; + } else { + incallBgTask = [app beginBackgroundTaskWithExpirationHandler:expirationHandler]; + } [[NSRunLoop currentRunLoop] addTimer:data->timer forMode:NSRunLoopCommonModes]; }