diff --git a/Classes/LinphoneAppDelegate.h b/Classes/LinphoneAppDelegate.h index 3428b1782..8b0076e3c 100644 --- a/Classes/LinphoneAppDelegate.h +++ b/Classes/LinphoneAppDelegate.h @@ -19,7 +19,7 @@ #import #import -#import + #import "LinphoneCoreSettingsStore.h" @@ -30,7 +30,6 @@ @interface LinphoneAppDelegate : NSObject { @private UIWindow *window; - CTCallCenter* callCenter; BOOL started; int savedMaxCall; diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index 3865666a1..259888f6a 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -56,17 +56,7 @@ #pragma mark - -- (void)handleGSMCallInteration: (id) cCenter { - CTCallCenter* ct = (CTCallCenter*) cCenter; - - int callCount = [ct.currentCalls count]; - /* pause current call, if any */ - LinphoneCall* call = linphone_core_get_current_call([LinphoneManager getLc]); - if (callCount>0 && call) { - [LinphoneLogger logc:LinphoneLoggerLog format:"Pausing SIP call"]; - linphone_core_pause_call([LinphoneManager getLc], call); - } -} + - (void)applicationDidEnterBackground:(UIApplication *)application{ [LinphoneLogger logc:LinphoneLoggerLog format:"applicationDidEnterBackground"]; @@ -94,13 +84,7 @@ } if (![[LinphoneManager instance] resignActive]) { - // destroying eventHandler if app cannot go in background. - // Otherwise if a GSM call happen and Linphone is resumed, - // the handler will be called before LinphoneCore is built. - // Then handler will be restored in appDidBecomeActive cb - callCenter.callEventHandler = nil; - [callCenter release]; - callCenter = nil; + } } @@ -111,8 +95,6 @@ [[LinphoneManager instance] becomeActive]; - // check call state at startup - [self handleGSMCallInteration:callCenter]; LinphoneCore* lc = [LinphoneManager getLc]; LinphoneCall* call = linphone_core_get_current_call(lc); @@ -131,17 +113,7 @@ } } -- (void)setupGSMInteraction { - if (callCenter == nil) { - callCenter = [[CTCallCenter alloc] init]; - callCenter.callEventHandler = ^(CTCall* call) { - // post on main thread - [self performSelectorOnMainThread:@selector(handleGSMCallInteration:) - withObject:callCenter - waitUntilDone:YES]; - }; - } -} + - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound |UIRemoteNotificationTypeBadge]; @@ -176,7 +148,7 @@ [[LinphoneManager instance] startLibLinphone]; } if([LinphoneManager isLcReady]) { - [self setupGSMInteraction]; + // Only execute one time at application start if(!started) { diff --git a/Classes/LinphoneManager.h b/Classes/LinphoneManager.h index 787828499..e96eb9bb2 100644 --- a/Classes/LinphoneManager.h +++ b/Classes/LinphoneManager.h @@ -22,6 +22,7 @@ #import #import #import +#import #import @@ -88,6 +89,7 @@ typedef struct _LinphoneManagerSounds { Connectivity connectivity; BOOL stopWaitingRegisters; UIBackgroundTaskIdentifier pausedCallBgTask; + CTCallCenter* callCenter; @public CallContext currentCallContextBeforeGoingBackground; diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index a23bc620b..d6256750b 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -378,15 +378,11 @@ static void linphone_iphone_display_status(struct _LinphoneCore * lc, const char - (void)onCall:(LinphoneCall*)call StateChanged:(LinphoneCallState)state withMessage:(const char *)message { // Handling wrapper - CTCallCenter* ct = [[CTCallCenter alloc] init]; - - int callCount = [ct.currentCalls count]; - if (callCount>0 && state==LinphoneCallIncomingReceived) { + if ([callCenter currentCalls]!=nil && state==LinphoneCallIncomingReceived) { [LinphoneLogger logc:LinphoneLoggerLog format:"Mobile call ongoing... rejecting call from [%s]",linphone_address_get_username(linphone_call_get_call_log(call)->from)]; linphone_core_terminate_call([LinphoneManager getLc], call); return; } - [ct release]; if(state == LinphoneCallReleased) { LinphoneCallAppData* data = linphone_call_get_user_pointer(call); @@ -657,8 +653,8 @@ static LinphoneCoreVTable linphonec_vtable = { #if HAVE_G729 libmsbcg729_init(); // load g729 plugin #endif + [self setupGSMInteraction]; /* Initialize linphone core*/ - [LinphoneLogger logc:LinphoneLoggerLog format:"Create linphonecore"]; linphone_core_enable_logs_with_cb((OrtpLogFunc)linphone_iphone_log_handler); theLinphoneCore = linphone_core_new (&linphonec_vtable @@ -758,6 +754,14 @@ static LinphoneCoreVTable linphonec_vtable = { - (void)destroyLibLinphone { [mIterateTimer invalidate]; + // destroying eventHandler if app cannot go in background. + // Otherwise if a GSM call happen and Linphone is resumed, + // the handler will be called before LinphoneCore is built. + // Then handler will be restored in appDidBecomeActive cb + callCenter.callEventHandler = nil; + [callCenter release]; + callCenter = nil; + AVAudioSession *audioSession = [AVAudioSession sharedInstance]; [audioSession setDelegate:nil]; @@ -807,6 +811,7 @@ static int comp_call_id (const LinphoneCall* call , const char *callid) { - (BOOL)resignActive { linphone_core_stop_dtmf_stream(theLinphoneCore); + return YES; } @@ -985,8 +990,8 @@ static void audioRouteChangeListenerCallback ( return; } - CTCallCenter* ct = [[CTCallCenter alloc] init]; - if ([ct.currentCalls count] > 0) { + + if ([callCenter currentCalls]!=nil) { [LinphoneLogger logc:LinphoneLoggerError format:"GSM call in progress, cancelling outgoing SIP call request"]; UIAlertView* error = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Cannot make call",nil) message:NSLocalizedString(@"Please terminate GSM call",nil) @@ -995,10 +1000,8 @@ static void audioRouteChangeListenerCallback ( otherButtonTitles:nil]; [error show]; [error release]; - [ct release]; return; } - [ct release]; LinphoneProxyConfig* proxyCfg; //get default proxy @@ -1194,4 +1197,27 @@ static void audioRouteChangeListenerCallback ( return [self lpConfigIntForKey:key forSection:section] == 1; } +#pragma GSM management + +- (void)setupGSMInteraction { + if (callCenter == nil) { + callCenter = [[CTCallCenter alloc] init]; + callCenter.callEventHandler = ^(CTCall* call) { + // post on main thread + [self performSelectorOnMainThread:@selector(handleGSMCallInteration:) + withObject:callCenter + waitUntilDone:YES]; + }; + } +} + +- (void)handleGSMCallInteration: (id) cCenter { + CTCallCenter* ct = (CTCallCenter*) cCenter; + /* pause current call, if any */ + LinphoneCall* call = linphone_core_get_current_call(theLinphoneCore); + if ([ct currentCalls]!=nil && call) { + [LinphoneLogger logc:LinphoneLoggerLog format:"Pausing SIP call"]; + linphone_core_pause_call(theLinphoneCore, call); + } +} @end