Skip to content

Commit 0f56b89

Browse files
committed
Merge branch '300-ios-allow-showing-caller-number-or-client-name'
2 parents ae5c978 + ca3a7ea commit 0f56b89

File tree

2 files changed

+65
-52
lines changed

2 files changed

+65
-52
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Next release
22

33
* Fix: [iOS] Missed call notifications now show caller name (or full number) on title, and "Missed call" text in body. [Issue #299](https://github.com/cybex-dev/twilio_voice/issues/299)
4+
* Feat: [iOS] show caller number or interpretted client name for reportingIncomingCall and missed call notification
45
* Docs: update CHANGELOG
56

67
## 0.3.2

ios/Classes/SwiftTwilioVoicePlugin.swift

Lines changed: 64 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -673,14 +673,18 @@ public class SwiftTwilioVoicePlugin: NSObject, FlutterPlugin, FlutterStreamHand
673673
let content = UNMutableNotificationContent()
674674
var userName:String?
675675
if var from = from{
676-
from = from.replacingOccurrences(of: "client:", with: "")
676+
if(from.contains("client:")) {
677+
from = from.replacingOccurrences(of: "client:", with: "")
678+
userName = self.clients[from];
679+
} else {
680+
userName = from
681+
}
677682
content.userInfo = ["type":"twilio-missed-call", "From":from]
678683
if let to = to{
679684
content.userInfo["To"] = to
680685
}
681-
userName = self.clients[from]
682686
}
683-
687+
684688
let title = userName ?? self.clients["defaultCaller"] ?? self.defaultCaller
685689
content.title = title
686690
content.body = NSLocalizedString("notification_missed_call_body", comment: "")
@@ -689,49 +693,49 @@ public class SwiftTwilioVoicePlugin: NSObject, FlutterPlugin, FlutterStreamHand
689693
let request = UNNotificationRequest(identifier: UUID().uuidString,
690694
content: content,
691695
trigger: trigger)
692-
696+
693697
notificationCenter.add(request) { (error) in
694698
if let error = error {
695699
print("Notification Error: ", error)
696700
}
697701
}
698-
702+
699703
}
700704
}
701705
}
702-
706+
703707
// MARK: TVOCallDelegate
704708
public func callDidStartRinging(call: Call) {
705709
let direction = (self.callOutgoing ? "Outgoing" : "Incoming")
706710
let from = (call.from ?? self.identity)
707711
let to = (call.to ?? self.callTo)
708712
self.sendPhoneCallEvents(description: "Ringing|\(from)|\(to)|\(direction)", isError: false)
709-
713+
710714
//self.placeCallButton.setTitle("Ringing", for: .normal)
711715
}
712-
716+
713717
public func callDidConnect(call: Call) {
714718
let direction = (self.callOutgoing ? "Outgoing" : "Incoming")
715719
let from = (call.from ?? self.identity)
716720
let to = (call.to ?? self.callTo)
717721
self.sendPhoneCallEvents(description: "Connected|\(from)|\(to)|\(direction)", isError: false)
718-
722+
719723
if let callKitCompletionCallback = callKitCompletionCallback {
720724
callKitCompletionCallback(true)
721725
}
722-
726+
723727
toggleAudioRoute(toSpeaker: false)
724728
}
725-
729+
726730
public func call(call: Call, isReconnectingWithError error: Error) {
727731
self.sendPhoneCallEvents(description: "Reconnecting", isError: false)
728-
732+
729733
}
730-
734+
731735
public func callDidReconnect(call: Call) {
732736
self.sendPhoneCallEvents(description: "Reconnected", isError: false)
733737
}
734-
738+
735739
public func callDidFailToConnect(call: Call, error: Error) {
736740
self.sendPhoneCallEvents(description: "LOG|Call failed to connect: \(error.localizedDescription)", isError: false)
737741
self.sendPhoneCallEvents(description: "Call Ended", isError: false)
@@ -743,47 +747,47 @@ public class SwiftTwilioVoicePlugin: NSObject, FlutterPlugin, FlutterStreamHand
743747
if let completion = self.callKitCompletionCallback {
744748
completion(false)
745749
}
746-
747-
750+
751+
748752
callKitProvider.reportCall(with: call.uuid!, endedAt: Date(), reason: CXCallEndedReason.failed)
749753
callDisconnected()
750754
}
751-
755+
752756
public func callDidDisconnect(call: Call, error: Error?) {
753757
self.sendPhoneCallEvents(description: "Call Ended", isError: false)
754758
if let error = error {
755759
self.sendPhoneCallEvents(description: "Call Failed: \(error.localizedDescription)", isError: true)
756760
}
757-
761+
758762
if !self.userInitiatedDisconnect {
759763
var reason = CXCallEndedReason.remoteEnded
760764
self.sendPhoneCallEvents(description: "LOG|User initiated disconnect", isError: false)
761765
if error != nil {
762766
reason = .failed
763767
}
764-
768+
765769
self.callKitProvider.reportCall(with: call.uuid!, endedAt: Date(), reason: reason)
766770
}
767-
771+
768772
callDisconnected()
769773
}
770-
774+
771775
func callDisconnected() {
772776
self.sendPhoneCallEvents(description: "LOG|Call Disconnected", isError: false)
773777
if (self.call != nil) {
774-
778+
775779
self.sendPhoneCallEvents(description: "LOG|Setting call to nil", isError: false)
776780
self.call = nil
777781
}
778782
if (self.callInvite != nil) {
779783
self.callInvite = nil
780784
}
781-
785+
782786
self.callOutgoing = false
783787
self.userInitiatedDisconnect = false
784-
788+
785789
}
786-
790+
787791
func isSpeakerOn() -> Bool {
788792
// Source: https://stackoverflow.com/a/51759708/4628115
789793
let currentRoute = AVAudioSession.sharedInstance().currentRoute
@@ -820,37 +824,37 @@ public class SwiftTwilioVoicePlugin: NSObject, FlutterPlugin, FlutterStreamHand
820824
}
821825
audioDevice.block()
822826
}
823-
827+
824828
// MARK: CXProviderDelegate
825829
public func providerDidReset(_ provider: CXProvider) {
826830
self.sendPhoneCallEvents(description: "LOG|providerDidReset:", isError: false)
827831
audioDevice.isEnabled = false
828832
}
829-
833+
830834
public func providerDidBegin(_ provider: CXProvider) {
831835
self.sendPhoneCallEvents(description: "LOG|providerDidBegin", isError: false)
832836
}
833-
837+
834838
public func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) {
835839
self.sendPhoneCallEvents(description: "LOG|provider:didActivateAudioSession:", isError: false)
836840
audioDevice.isEnabled = true
837841
}
838-
842+
839843
public func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) {
840844
self.sendPhoneCallEvents(description: "LOG|provider:didDeactivateAudioSession:", isError: false)
841845
audioDevice.isEnabled = false
842846
}
843-
847+
844848
public func provider(_ provider: CXProvider, timedOutPerforming action: CXAction) {
845849
self.sendPhoneCallEvents(description: "LOG|provider:timedOutPerformingAction:", isError: false)
846850
}
847-
851+
848852
public func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
849853
self.sendPhoneCallEvents(description: "LOG|provider:performStartCallAction:", isError: false)
850-
851-
854+
855+
852856
provider.reportOutgoingCall(with: action.callUUID, startedConnectingAt: Date())
853-
857+
854858
self.performVoiceCall(uuid: action.callUUID, client: "") { (success) in
855859
if (success) {
856860
self.sendPhoneCallEvents(description: "LOG|provider:performAnswerVoiceCall() successful", isError: false)
@@ -861,26 +865,26 @@ public class SwiftTwilioVoicePlugin: NSObject, FlutterPlugin, FlutterStreamHand
861865
}
862866
action.fulfill()
863867
}
864-
868+
865869
public func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
866870
self.sendPhoneCallEvents(description: "LOG|provider:performAnswerCallAction:", isError: false)
867-
868-
871+
872+
869873
self.performAnswerVoiceCall(uuid: action.callUUID) { (success) in
870874
if success {
871875
self.sendPhoneCallEvents(description: "LOG|provider:performAnswerVoiceCall() successful", isError: false)
872876
} else {
873877
self.sendPhoneCallEvents(description: "LOG|provider:performAnswerVoiceCall() failed:", isError: false)
874878
}
875879
}
876-
880+
877881
action.fulfill()
878882
}
879-
883+
880884
public func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
881885
self.sendPhoneCallEvents(description: "LOG|provider:performEndCallAction:", isError: false)
882-
883-
886+
887+
884888
if (self.callInvite != nil) {
885889
self.sendPhoneCallEvents(description: "LOG|provider:performEndCallAction: rejecting call", isError: false)
886890
self.callInvite?.reject()
@@ -891,7 +895,7 @@ public class SwiftTwilioVoicePlugin: NSObject, FlutterPlugin, FlutterStreamHand
891895
}
892896
action.fulfill()
893897
}
894-
898+
895899
public func provider(_ provider: CXProvider, perform action: CXSetHeldCallAction) {
896900
self.sendPhoneCallEvents(description: "LOG|provider:performSetHeldAction:", isError: false)
897901
if let call = self.call {
@@ -901,32 +905,32 @@ public class SwiftTwilioVoicePlugin: NSObject, FlutterPlugin, FlutterStreamHand
901905
action.fail()
902906
}
903907
}
904-
908+
905909
public func provider(_ provider: CXProvider, perform action: CXSetMutedCallAction) {
906910
self.sendPhoneCallEvents(description: "LOG|provider:performSetMutedAction:", isError: false)
907-
911+
908912
if let call = self.call {
909913
call.isMuted = action.isMuted
910914
action.fulfill()
911915
} else {
912916
action.fail()
913917
}
914918
}
915-
919+
916920
// MARK: Call Kit Actions
917921
func performStartCallAction(uuid: UUID, handle: String) {
918922
let callHandle = CXHandle(type: .generic, value: handle)
919923
let startCallAction = CXStartCallAction(call: uuid, handle: callHandle)
920924
let transaction = CXTransaction(action: startCallAction)
921-
925+
922926
callKitCallController.request(transaction) { error in
923927
if let error = error {
924928
self.sendPhoneCallEvents(description: "LOG|StartCallAction transaction request failed: \(error.localizedDescription)", isError: false)
925929
return
926930
}
927-
931+
928932
self.sendPhoneCallEvents(description: "LOG|StartCallAction transaction request successful", isError: false)
929-
933+
930934
let callUpdate = CXCallUpdate()
931935
callUpdate.remoteHandle = callHandle
932936
callUpdate.localizedCallerName = self.clients[handle] ?? self.clients["defaultCaller"] ?? self.defaultCaller
@@ -935,17 +939,25 @@ public class SwiftTwilioVoicePlugin: NSObject, FlutterPlugin, FlutterStreamHand
935939
callUpdate.supportsGrouping = false
936940
callUpdate.supportsUngrouping = false
937941
callUpdate.hasVideo = false
938-
942+
939943
self.callKitProvider.reportCall(with: uuid, updated: callUpdate)
940944
}
941945
}
942-
946+
943947
func reportIncomingCall(from: String, uuid: UUID) {
944948
let callHandle = CXHandle(type: .generic, value: from)
945-
949+
950+
var callerName: String?;
951+
if(from.contains("client:")) {
952+
var clientName = from.replacingOccurrences(of: "client:", with: "")
953+
callerName = self.clients[clientName];
954+
} else {
955+
callerName = from
956+
}
957+
946958
let callUpdate = CXCallUpdate()
947959
callUpdate.remoteHandle = callHandle
948-
callUpdate.localizedCallerName = clients[from] ?? self.clients["defaultCaller"] ?? defaultCaller
960+
callUpdate.localizedCallerName = callerName ?? self.clients["defaultCaller"] ?? defaultCaller
949961
callUpdate.supportsDTMF = true
950962
callUpdate.supportsHolding = true
951963
callUpdate.supportsGrouping = false

0 commit comments

Comments
 (0)