Skip to content

Commit e6483e2

Browse files
authored
Merge pull request #306 from cybex-dev/feat_enable_call_logging
Adds iOS call logging support
2 parents 0e64741 + d10bcc4 commit e6483e2

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* Feat: [Web] Update internal [CallStatus] mapping method.
1717
* Fix: [Web] Await Twilio Device `register()` and `unregister()` method calls.
1818
* Fix: [Web] Prevent duplicate `TwilioVoiceWeb` instances.
19+
* Feat: [iOS] Add support for call logging via `enableCallLogging(bool)` to record call in recents. No other platform currently supports this, see [NOTES.md](NOTES.md#limitations) for more details.
1920
* Feat: update example.
2021
* Docs: update CHANGELOG
2122

NOTES.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@ end
9292

9393
## Limitations
9494

95+
### Android
96+
97+
Android `ConnectionService` provides the fundamentals to managing calls, including but not limited to call logging. Using a Managed `ConnectionService` means that call logging is handled by the system's "Phone App", and so there is not access or control over call logging at this time.
98+
9599
### macOS
96100

97-
Clearly, macOS isn't uppermost in mind when looking at a mobile first platform like Flutter. There are some functionality limitations for the platform/interop such as [UIImage](https://docs.flutter.dev/ui/assets-and-images#loading-ios-images-in-flutter) support and Twilio Voice library support as a whole. Hopefully we'll be seeing these implemented in future.
101+
Clearly, macOS isn't uppermost in mind when looking at a mobile first platform like Flutter. There are some functionality limitations for the platform/interop such as [UIImage](https://docs.flutter.dev/ui/assets-and-images#loading-ios-images-in-flutter) support and Twilio Voice library support as a whole. Hopefully we'll be seeing these implemented in future.
102+
103+
With respect to CallKit integration for macOS, there isn't any direct support for CallKit other than via MacCatalyst which at present is somewhat out of scope for the project at this time.
104+
105+
106+
### Web
107+
108+
As Web uses a custom [WebCallkit](https://github.com/cybex-dev/web_callkit) integration, this facilitates basic call management and browser notification integration. Call logging is not supported at this time.

ios/Classes/SwiftTwilioVoicePlugin.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class SwiftTwilioVoicePlugin: NSObject, FlutterPlugin, FlutterStreamHand
1010
let callObserver = CXCallObserver()
1111

1212
final let defaultCallKitIcon = "callkit_icon"
13+
final let callLoggingEnabledKey = "TV_CALL_LOGGING_ENABLED"
1314
var callKitIcon: String?
1415

1516
var _result: FlutterResult?
@@ -61,6 +62,8 @@ public class SwiftTwilioVoicePlugin: NSObject, FlutterPlugin, FlutterStreamHand
6162
configuration.maximumCallGroups = 1
6263
configuration.maximumCallsPerCallGroup = 1
6364
let defaultIcon = UserDefaults.standard.string(forKey: defaultCallKitIcon) ?? defaultCallKitIcon
65+
let callLoggingEnabled = UserDefaults.standard.optionalBool(forKey: callLoggingEnabledKey) ?? true
66+
configuration.includesCallsInRecents = callLoggingEnabled
6467

6568
clients = UserDefaults.standard.object(forKey: kClientList) as? [String:String] ?? [:]
6669
callKitProvider = CXProvider(configuration: configuration)
@@ -356,10 +359,27 @@ public class SwiftTwilioVoicePlugin: NSObject, FlutterPlugin, FlutterStreamHand
356359
// update icon & persist
357360
result(updateCallKitIcon(icon: newIcon))
358361
return
362+
} else if flutterCall.method == "enableCallLogging" {
363+
let value = arguments["enabled"] as? Bool ?? true
364+
365+
result(updateEnableCallLogging(value))
366+
return
359367
}
360368
result(true)
361369
}
362370

371+
/// Set and persist call logging in app preferences
372+
/// - Parameter value: value, true if it should be enabled
373+
func updateEnableCallLogging(_ value: Bool) -> Bool {
374+
// Updating callkit configuration
375+
let configuration = callKitProvider.configuration
376+
configuration.includesCallsInRecents = value
377+
378+
// Save and persist setting
379+
UserDefaults.standard.set(value, forKey: callLoggingEnabledKey)
380+
return true;
381+
}
382+
363383
/// Updates the CallkitProvider configuration with a new icon, and saves this change to future use.
364384
/// - Parameter icon: icon path / name
365385
/// - Returns: true if succesful

lib/_internal/method_channel/twilio_voice_method_channel.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,14 @@ class MethodChannelTwilioVoice extends TwilioVoicePlatform {
442442
// TODO: implement updateSounds
443443
throw UnimplementedError();
444444
}
445+
446+
@override
447+
Future<void> enableCallLogging({bool enable = true}) {
448+
if (defaultTargetPlatform != TargetPlatform.iOS) {
449+
return Future.value();
450+
}
451+
return _channel.invokeMethod('enableCallLogging', <String, dynamic>{"enable": enable});
452+
}
445453
}
446454

447455
ActiveCall createCallFromState(String state, {CallDirection? callDirection, bool initiated = false}) {

lib/_internal/platform_interface/twilio_voice_platform_interface.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,9 @@ abstract class TwilioVoicePlatform extends SharedPlatformInterface {
197197

198198
/// Sends call events
199199
CallEvent parseCallEvent(String state);
200+
201+
/// Enable or disable call logging in call manager, or phone app recents.
202+
///
203+
/// Defaults to true.
204+
Future<void> enableCallLogging({bool enable = true});
200205
}

0 commit comments

Comments
 (0)