From a1583acefdd0bc5abe606cf36d5acc4ab85f982d Mon Sep 17 00:00:00 2001 From: Rehan Date: Mon, 11 Nov 2024 17:34:34 +0500 Subject: [PATCH 1/2] chore: configure ios user agent client source --- .../Bridge/SdkClientConfiguration.swift | 28 +++++++++++++++++++ ios/Classes/SwiftCustomerIoPlugin.swift | 3 ++ 2 files changed, 31 insertions(+) create mode 100644 ios/Classes/Bridge/SdkClientConfiguration.swift diff --git a/ios/Classes/Bridge/SdkClientConfiguration.swift b/ios/Classes/Bridge/SdkClientConfiguration.swift new file mode 100644 index 0000000..6fc396a --- /dev/null +++ b/ios/Classes/Bridge/SdkClientConfiguration.swift @@ -0,0 +1,28 @@ +import CioInternalCommon + +/// Extension on `SdkClient` to provide configuration functionality. +/// +/// **Note**: Due to Swift limitations with static methods in protocol extensions, static functions +/// in this extension should be called using `CustomerIOSdkClient.` to ensure correct behavior. +extension SdkClient { + + /// Configures and overrides the shared `SdkClient` instance with provided parameters. + /// + /// - Parameter args: Dictionary containing values required for `SdkClient` protocol. + /// - Returns: Configured `SdkClient` instance. Returns the existing shared client if required parameters are missing. + @available(iOSApplicationExtension, unavailable) + @discardableResult + static func configure(using args: [String: Any?]) -> SdkClient { + guard let source = args["source"] as? String, + let version = args["version"] as? String + else { + DIGraphShared.shared.logger.error("Missing required parameters for SdkClient configuration in args: \(args)") + return DIGraphShared.shared.sdkClient + } + + let client = CustomerIOSdkClient(source: source, sdkVersion: version) + DIGraphShared.shared.override(value: client, forType: SdkClient.self) + + return DIGraphShared.shared.sdkClient + } +} diff --git a/ios/Classes/SwiftCustomerIoPlugin.swift b/ios/Classes/SwiftCustomerIoPlugin.swift index 8f85f0a..78ae4c0 100644 --- a/ios/Classes/SwiftCustomerIoPlugin.swift +++ b/ios/Classes/SwiftCustomerIoPlugin.swift @@ -168,6 +168,9 @@ public class SwiftCustomerIoPlugin: NSObject, FlutterPlugin { private func initialize(params : Dictionary){ do { + // Configure and override SdkClient for Flutter before initializing native SDK + CustomerIOSdkClient.configure(using: params) + // Initialize native SDK with provided config let sdkConfigBuilder = try SDKConfigBuilder.create(from: params) CustomerIO.initialize(withConfig: sdkConfigBuilder.build()) From 536b4f2aaff655282ac693acf0e3af66ccc55ea6 Mon Sep 17 00:00:00 2001 From: Rehan Date: Tue, 12 Nov 2024 12:39:26 +0500 Subject: [PATCH 2/2] doc fix --- ios/Classes/Bridge/SdkClientConfiguration.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ios/Classes/Bridge/SdkClientConfiguration.swift b/ios/Classes/Bridge/SdkClientConfiguration.swift index 6fc396a..a0d21cd 100644 --- a/ios/Classes/Bridge/SdkClientConfiguration.swift +++ b/ios/Classes/Bridge/SdkClientConfiguration.swift @@ -8,7 +8,8 @@ extension SdkClient { /// Configures and overrides the shared `SdkClient` instance with provided parameters. /// - /// - Parameter args: Dictionary containing values required for `SdkClient` protocol. + /// - Parameters: + /// - using: Dictionary containing values required for `SdkClient` protocol. /// - Returns: Configured `SdkClient` instance. Returns the existing shared client if required parameters are missing. @available(iOSApplicationExtension, unavailable) @discardableResult