From 37dd2841ddbf252b8a6688345b47ca90aa70a89b Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Tue, 6 Mar 2012 17:05:45 +0100 Subject: [PATCH] Forbid SIP calls if GSM call is active --- Classes/LinphoneAppDelegate.m | 42 +++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index d84fa8dd9..08ab9de54 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -22,6 +22,9 @@ #import "ContactPickerDelegate.h" #import "AddressBook/ABPerson.h" +#import "CoreTelephony/CTCallCenter.h" +#import "CoreTelephony/CTCall.h" + #import "ConsoleViewController.h" #import "MoreViewController.h" #include "CallHistoryTableViewController.h" @@ -175,9 +178,44 @@ int __aeabi_idiv(int a, int b) { [[LinphoneManager instance] setCallDelegate:myPhoneViewController]; [[LinphoneManager instance] startLibLinphone]; - + [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound]; - + + UIDevice* device = [UIDevice currentDevice]; + BOOL backgroundSupported = false; + if ([device respondsToSelector:@selector(isMultitaskingSupported)]){ + backgroundSupported = device.multitaskingSupported; + } + if(backgroundSupported){ + [[LinphoneManager instance] kickOffBackgroundTCPConnection]; + NSLog(@"We are using my method"); + } + + CTCallCenter* ct = [[CTCallCenter alloc] init]; + ct.callEventHandler = ^(CTCall* call) { + @synchronized([LinphoneManager instance]) { + if (call.callState == CTCallStateDisconnected) { + NSLog(@"GSM call disconnected"); + if ([ct.currentCalls count] > 0) { + NSLog(@"There are still some ongoing GSM call: disable SIP calls"); + linphone_core_set_max_calls([LinphoneManager getLc], 0); + } else { + NSLog(@"Re-enabling SIP calls"); + linphone_core_set_max_calls([LinphoneManager getLc], 3); + } + } else { + NSLog(@"GSM call existing"); + /* pause current call, if any */ + LinphoneCall* call = linphone_core_get_current_call([LinphoneManager getLc]); + if (call) { + NSLog(@"Pausing SIP call"); + linphone_core_pause_call([LinphoneManager getLc], call); + } + NSLog(@"Disabling SIP calls"); + linphone_core_set_max_calls([LinphoneManager getLc], 0); + } + } + }; return YES; }