diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index 259888f6a..13f849f29 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -211,14 +211,8 @@ } - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { - if([notification.userInfo objectForKey:@"call"] != nil) { - LinphoneCall* call; - [(NSData*)[notification.userInfo objectForKey:@"call"] getBytes:&call]; - if (!call) { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Local notification received with nil call"]; - return; - } - linphone_core_accept_call([LinphoneManager getLc], call); + if([notification.userInfo objectForKey:@"callId"] != nil) { + [[LinphoneManager instance] acceptCallForCallId:[notification.userInfo objectForKey:@"callId"]]; } else if([notification.userInfo objectForKey:@"chat"] != nil) { NSString *remoteContact = (NSString*)[notification.userInfo objectForKey:@"chat"]; // Go to ChatRoom view diff --git a/Classes/LinphoneManager.h b/Classes/LinphoneManager.h index e29a0e94d..4e7cb15c4 100644 --- a/Classes/LinphoneManager.h +++ b/Classes/LinphoneManager.h @@ -115,6 +115,7 @@ typedef struct _LinphoneManagerSounds { - (void)enableAutoAnswerForCallId:(NSString*) callid; - (void)addPushTokenToProxyConfig: (LinphoneProxyConfig*)cfg; - (BOOL)shouldAutoAcceptCallForCallId:(NSString*) callId; +- (void)acceptCallForCallId:(NSString*)callid; - (void)waitForRegisterToArrive; + (void)kickOffNetworkConnection; diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index bf4da5a68..492854388 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -427,9 +427,8 @@ static void linphone_iphone_display_status(struct _LinphoneCore * lc, const char data->notification.alertBody =[NSString stringWithFormat:NSLocalizedString(@"IC_MSG",nil), address]; data->notification.alertAction = NSLocalizedString(@"Answer", nil); data->notification.soundName = @"ring.caf"; - data->notification.userInfo = [NSDictionary dictionaryWithObject:[NSData dataWithBytes:&call length:sizeof(call)] forKey:@"call"]; + data->notification.userInfo = [NSDictionary dictionaryWithObject:callId forKey:@"callId"]; - [[LinphoneManager instance] enableAutoAnswerForCallId:callId]; [[UIApplication sharedApplication] presentLocalNotificationNow:data->notification]; if (!incallBgTask){ @@ -844,10 +843,24 @@ static LinphoneCoreVTable linphonec_vtable = { } } -static int comp_call_id (const LinphoneCall* call , const char *callid) { + +static int comp_call_id(const LinphoneCall* call , const char *callid) { return strcmp(linphone_call_get_call_log(call)->call_id, callid); } -- (void)enableAutoAnswerForCallId:(NSString*) callid{ + +- (void)acceptCallForCallId:(NSString*)callid { + //first, make sure this callid is not already involved in a call + if ([LinphoneManager isLcReady]) { + MSList* calls = (MSList*)linphone_core_get_calls([LinphoneManager getLc]); + MSList* call = ms_list_find_custom(calls, (MSCompareFunc)comp_call_id, [callid UTF8String]); + if (call != NULL) { + linphone_core_accept_call(theLinphoneCore, (LinphoneCall*)call->data); + return; + }; + } +} + +- (void)enableAutoAnswerForCallId:(NSString*) callid { //first, make sure this callid is not already involved in a call if ([LinphoneManager isLcReady]) { MSList* calls = (MSList*)linphone_core_get_calls([LinphoneManager getLc]); @@ -862,7 +875,7 @@ static int comp_call_id (const LinphoneCall* call , const char *callid) { } -- (BOOL)shouldAutoAcceptCallForCallId:(NSString*) callId{ +- (BOOL)shouldAutoAcceptCallForCallId:(NSString*) callId { for (NSString* pendingNotif in pendindCallIdFromRemoteNotif) { if ([pendingNotif compare:callId] == NSOrderedSame) { [pendindCallIdFromRemoteNotif removeObject:pendingNotif];