diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index bcb6c6957..a456eea38 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -441,12 +441,8 @@ return; } - if ([self addLongTaskIDforCallID:callId] && [UIApplication sharedApplication].applicationState != UIApplicationStateActive) { - if ([loc_key isEqualToString:@"IC_MSG"]) - [LinphoneManager.instance startPushLongRunningTask:FALSE callId:callId]; - else if ([loc_key isEqualToString:@"IM_MSG"]) - [LinphoneManager.instance startPushLongRunningTask:TRUE callId:callId]; - } + if ([self addLongTaskIDforCallID:callId] && [UIApplication sharedApplication].applicationState != UIApplicationStateActive) + [LinphoneManager.instance startPushLongRunningTask:loc_key callId:callId]; // if we receive a push notification, it is probably because our TCP background socket was no more working. // As a result, break it and refresh registers in order to make sure to receive incoming INVITE or MESSAGE diff --git a/Classes/LinphoneManager.h b/Classes/LinphoneManager.h index 7f5f66259..76dc4fd23 100644 --- a/Classes/LinphoneManager.h +++ b/Classes/LinphoneManager.h @@ -109,6 +109,7 @@ typedef struct _LinphoneManagerSounds { Connectivity connectivity; UIBackgroundTaskIdentifier pausedCallBgTask; UIBackgroundTaskIdentifier incallBgTask; + UIBackgroundTaskIdentifier pushBgTaskRefer; UIBackgroundTaskIdentifier pushBgTaskCall; UIBackgroundTaskIdentifier pushBgTaskMsg; CTCallCenter* mCallCenter; @@ -143,7 +144,7 @@ typedef struct _LinphoneManagerSounds { - (LinphoneCall *)callByCallId:(NSString *)call_id; - (void)cancelLocalNotifTimerForCallId:(NSString*)callid; - (void)alertLIME:(LinphoneChatRoom *)room; -- (void)startPushLongRunningTask:(BOOL)msg callId:(NSString *)callId; +- (void)startPushLongRunningTask:(NSString *)loc_key callId:(NSString *)callId; + (BOOL)langageDirectionIsRTL; + (void)kickOffNetworkConnection; - (void)setupNetworkReachabilityCallback; diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 30b0b2c53..4ad81a3c8 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -2142,8 +2142,8 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) { [[UIApplication sharedApplication] backgroundTimeRemaining]); } -- (void)startPushLongRunningTask:(BOOL)msg callId:(NSString *)callId { - if (msg) { +- (void)startPushLongRunningTask:(NSString *)loc_key callId:(NSString *)callId { + if ([loc_key isEqualToString:@"IM_MSG"]) { [[UIApplication sharedApplication] endBackgroundTask:pushBgTaskMsg]; pushBgTaskMsg = 0; pushBgTaskMsg = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ @@ -2174,7 +2174,7 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) { }]; LOGI(@"Message long running task started for call-id [%@], remaining [%g s] because a push has been received", callId, [[UIApplication sharedApplication] backgroundTimeRemaining]); - } else { + } else if ([loc_key isEqualToString:@"IC_MSG"]) { [[UIApplication sharedApplication] endBackgroundTask:pushBgTaskCall]; pushBgTaskCall = 0; pushBgTaskCall = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ @@ -2205,6 +2205,23 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) { }]; LOGI(@"Call long running task started for call-id [%@], remaining [%g s] because a push has been received", callId, [[UIApplication sharedApplication] backgroundTimeRemaining]); + } else if ([loc_key isEqualToString:@"IC_SIL"]) { + [[UIApplication sharedApplication] endBackgroundTask:pushBgTaskRefer]; + pushBgTaskRefer = 0; + pushBgTaskRefer = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ + // Could be or not an error since the app doesn't know when to end the background task for a REFER + // TODO: Manage pushes in the SDK + if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) + LOGI(@"Incomming refer long running task with call-id [%@] has expired", callId); + + for (NSString *key in [LinphoneManager.instance.pushDict allKeys]) { + [LinphoneManager.instance.pushDict setValue:[NSNumber numberWithInt:0] forKey:key]; + } + [[UIApplication sharedApplication] endBackgroundTask:pushBgTaskRefer]; + pushBgTaskRefer = 0; + }]; + LOGI(@"Refer long running task started for call-id [%@], remaining [%g s] because a push has been received", + callId, [[UIApplication sharedApplication] backgroundTimeRemaining]); } }