From b0e83b970a4ee58d4ed724bda4f45b6d892f7d08 Mon Sep 17 00:00:00 2001 From: Danmei Chen Date: Tue, 24 Mar 2020 09:17:08 +0100 Subject: [PATCH] remove useless code --- Classes/CallManager.swift | 10 ------ Classes/LinphoneAppDelegate.m | 66 +++------------------------------- Classes/ProviderDelegate.swift | 2 +- 3 files changed, 5 insertions(+), 73 deletions(-) diff --git a/Classes/CallManager.swift b/Classes/CallManager.swift index 8586492c7..1874c746a 100644 --- a/Classes/CallManager.swift +++ b/Classes/CallManager.swift @@ -43,7 +43,6 @@ import AVFoundation @objc var speakerEnabled : Bool = false @objc var bluetoothEnabled : Bool = false @objc var nextCallIsTransfer: Bool = false - @objc var callHandled: String = "" fileprivate override init() { @@ -182,15 +181,6 @@ import AVFoundation } } - // There is an error before display an incoming call. Attention, it's unnormal in this case! - @objc func displayForkIncomingCall() { - if CallManager.incomingCallMustBeDisplayed() { - // Display the call in any way, otherwise it will cause a crash. - Log.directLog(BCTBX_LOG_ERROR, text: "CallKit: please check the pushkit notification, there must be something wrong!") - providerDelegate.reportForkIncomingCall(); - } - } - func displayIncomingCall(call:Call?, handle: String, hasVideo: Bool, callId: String) { let uuid = UUID() let callInfo = CallInfo.newIncomingCallInfo(callId: callId) diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index 0d8b3c560..b7c7a8bc7 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -58,7 +58,6 @@ - (void)applicationDidEnterBackground:(UIApplication *)application { LOGI(@"%@", NSStringFromSelector(_cmd)); [LinphoneManager.instance enterBackgroundMode]; - CallManager.instance.callHandled = @""; LinphoneCall *call = linphone_core_get_current_call(LC); if (!call) { @@ -426,47 +425,16 @@ } } --(void)displayfailedcall { - -} - - (void)processRemoteNotification:(NSDictionary *)userInfo { - // TODO: it works only for calls. + // support only for calls NSDictionary *aps = [userInfo objectForKey:@"aps"]; - if (!aps) { - LOGE(@"Notification [%p] was empy, it's impossible to process it.", userInfo); - [CallManager.instance displayForkIncomingCall]; - return; - } - - NSString *loc_key = [aps objectForKey:@"loc-key"] ?: [[aps objectForKey:@"alert"] objectForKey:@"loc-key"]; - if (!loc_key) { - LOGE(@"Notification [%p] has no loc_key, it's impossible to process it.", userInfo); - [CallManager.instance displayForkIncomingCall]; - return; - } - + //NSString *loc_key = [aps objectForKey:@"loc-key"] ?: [[aps objectForKey:@"alert"] objectForKey:@"loc-key"]; NSString *callId = [aps objectForKey:@"call-id"] ?: @""; - if ([callId isEqualToString:@""]) { - [CallManager.instance displayForkIncomingCall]; - } - if (![loc_key isEqualToString:@"IC_MSG"]) { - [CallManager.instance displayForkIncomingCall]; - } - if([CallManager incomingCallMustBeDisplayed]) { + if([CallManager callKitEnabled]) { // Since ios13, a new Incoming call must be displayed when the callkit is enabled and app is in background. // Otherwise it will cause a crash. - if ([CallManager.instance.callHandled isEqualToString:callId]) { - LOGD(@"Notification has traited (Background)."); - } else { - CallManager.instance.callHandled = callId; - if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive && [self addLongTaskIDforCallID:callId]) { - [LinphoneManager.instance startPushLongRunningTask:loc_key callId:callId]; - } - [LinphoneManager.instance addPushCallId:callId]; - [CallManager.instance displayIncomingCallWithCallId:callId]; - } + [CallManager.instance displayIncomingCallWithCallId:callId]; } else { if (linphone_core_get_calls(LC)) { // if there are calls, obviously our TCP socket shall be working @@ -474,20 +442,6 @@ return; } - if ([CallManager.instance.callHandled isEqualToString:callId]) { - LOGD(@"Notification has traited (Foreground)."); - return; - } - NSString *uuid = [NSString stringWithFormat:@"", [LinphoneManager.instance lpConfigStringForKey:@"uuid" inSection:@"misc" withDefault:NULL]]; - NSString *sipInstance = [aps objectForKey:@"uuid"]; - if (sipInstance && uuid && ![sipInstance isEqualToString:uuid]) { - LOGE(@"Notification [%p] was intended for another device, ignoring it.", userInfo); - LOGD(@"My sip instance is: [%@], push was intended for: [%@].", uuid, sipInstance); - return; - } - if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive && [self addLongTaskIDforCallID:callId]) - [LinphoneManager.instance startPushLongRunningTask:loc_key callId:callId]; - if ([callId isEqualToString:@""]) { // Present apn pusher notifications for info LOGD(@"Notification [%p] came from flexisip-pusher.", userInfo); @@ -504,19 +458,7 @@ LOGD(error.description); } }]; - } else { - UILocalNotification *notification = [[UILocalNotification alloc] init]; - notification.repeatInterval = 0; - notification.alertBody = @"Push notification received !"; - notification.alertTitle = @"APN Pusher"; - [[UIApplication sharedApplication] presentLocalNotificationNow:notification]; } - } else if (![callId isEqualToString:@""] && [loc_key isEqualToString:@"IC_MSG"] && [CallManager callKitEnabled]) { - // Report a new Incoming call when app is in foreground. - if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive && [self addLongTaskIDforCallID:callId]) { - [LinphoneManager.instance startPushLongRunningTask:loc_key callId:callId]; - } - [LinphoneManager.instance addPushCallId:callId]; } } diff --git a/Classes/ProviderDelegate.swift b/Classes/ProviderDelegate.swift index 196e77fc7..cf48155f3 100644 --- a/Classes/ProviderDelegate.swift +++ b/Classes/ProviderDelegate.swift @@ -133,6 +133,7 @@ class ProviderDelegate: NSObject { // MARK: - CXProviderDelegate extension ProviderDelegate: CXProviderDelegate { func provider(_ provider: CXProvider, perform action: CXEndCallAction) { + action.fulfill() let uuid = action.callUUID let callId = callInfos[uuid]?.callId @@ -147,7 +148,6 @@ extension ProviderDelegate: CXProviderDelegate { CallManager.instance().terminateCall(call: call.getCobject); Log.directLog(BCTBX_LOG_MESSAGE, text: "CallKit: Call ended with call-id: \(String(describing: callId)) an UUID: \(uuid.description).") } - action.fulfill() } func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {