Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: configure ios user agent client source #169

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading