From 9307a25a5158a2dc3d55d9cf3eaf3497e37dfc0f Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Fri, 13 Oct 2017 16:33:38 +0200 Subject: [PATCH] Decline incoming Call when CallKit returns DND --- Classes/LinphoneManager.m | 2 +- Classes/ProviderDelegate.h | 2 +- Classes/ProviderDelegate.m | 17 ++++++++++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 2debfe0a2..fa3f3ed25 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -711,7 +711,7 @@ static void linphone_iphone_display_status(struct _LinphoneCore *lc, const char video = ([UIApplication sharedApplication].applicationState == UIApplicationStateActive && linphone_core_get_video_policy(LC)->automatically_accept && linphone_call_params_video_enabled(linphone_call_get_remote_params(call))); - [LinphoneManager.instance.providerDelegate reportIncomingCallwithUUID:uuid handle:address video:video]; + [LinphoneManager.instance.providerDelegate reportIncomingCall:call withUUID:uuid handle:address video:video]; #else [PhoneMainView.instance displayIncomingCall:call]; #endif diff --git a/Classes/ProviderDelegate.h b/Classes/ProviderDelegate.h index 488a4316e..964aac680 100644 --- a/Classes/ProviderDelegate.h +++ b/Classes/ProviderDelegate.h @@ -23,7 +23,7 @@ @property BOOL pendingCallVideo; @property int callKitCalls; -- (void)reportIncomingCallwithUUID:(NSUUID *)uuid handle:(NSString *)handle video:(BOOL)video; +- (void)reportIncomingCall:(LinphoneCall *) call withUUID:(NSUUID *)uuid handle:(NSString *)handle video:(BOOL)video; - (void)config; - (void)configAudioSession:(AVAudioSession *)audioSession; @end diff --git a/Classes/ProviderDelegate.m b/Classes/ProviderDelegate.m index 3479aaaee..6178d2f85 100644 --- a/Classes/ProviderDelegate.m +++ b/Classes/ProviderDelegate.m @@ -71,7 +71,7 @@ } } -- (void)reportIncomingCallwithUUID:(NSUUID *)uuid handle:(NSString *)handle video:(BOOL)video { +- (void)reportIncomingCall:(LinphoneCall *) call withUUID:(NSUUID *)uuid handle:(NSString *)handle video:(BOOL)video; { // Create update to describe the incoming call and caller CXCallUpdate *update = [[CXCallUpdate alloc] init]; update.remoteHandle = [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:handle]; @@ -80,13 +80,24 @@ update.supportsGrouping = TRUE; update.supportsUngrouping = TRUE; update.hasVideo = video; - + linphone_call_ref(call); // Report incoming call to system LOGD(@"CallKit: report new incoming call"); + [self.provider reportNewIncomingCallWithUUID:uuid update:update completion:^(NSError *error) { - }]; + if (error) { + LOGE(@"CallKit: cannot complete incoming call from [%@] caused by [%@]",handle,[error localizedDescription]); + if ( [error code] == CXErrorCodeIncomingCallErrorFilteredByDoNotDisturb + || [error code] == CXErrorCodeIncomingCallErrorFilteredByBlockList) { + linphone_call_decline(call,LinphoneReasonBusy); /*to give a chance for other devices to answer*/ + } else { + linphone_call_decline(call,LinphoneReasonUnknown); + } + } + linphone_call_unref(call); + }]; } - (void)setPendingCall:(LinphoneCall *)pendingCall {