Skip to content

Commit

Permalink
chore: configure ios user agent client source
Browse files Browse the repository at this point in the history
  • Loading branch information
mrehan27 committed Nov 11, 2024
1 parent 76ea710 commit a1583ac
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ios/Classes/Bridge/SdkClientConfiguration.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
3 changes: 3 additions & 0 deletions ios/Classes/SwiftCustomerIoPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ public class SwiftCustomerIoPlugin: NSObject, FlutterPlugin {

private func initialize(params : Dictionary<String, AnyHashable>){
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())

Expand Down

0 comments on commit a1583ac

Please sign in to comment.