diff --git a/ios/Classes/Bridge/SdkClientConfiguration.swift b/ios/Classes/Bridge/SdkClientConfiguration.swift new file mode 100644 index 0000000..a0d21cd --- /dev/null +++ b/ios/Classes/Bridge/SdkClientConfiguration.swift @@ -0,0 +1,29 @@ +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. + /// + /// - 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 + 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())