diff --git a/ConfidenceDemoApp/ConfidenceDemoApp/ConfidenceDemoApp.swift b/ConfidenceDemoApp/ConfidenceDemoApp/ConfidenceDemoApp.swift index 7b953607..309fef04 100644 --- a/ConfidenceDemoApp/ConfidenceDemoApp/ConfidenceDemoApp.swift +++ b/ConfidenceDemoApp/ConfidenceDemoApp/ConfidenceDemoApp.swift @@ -36,6 +36,9 @@ extension ConfidenceDemoApp { // NOTE: Using a random UUID for each app start is not advised and can result in getting stale values. let ctx = MutableContext(targetingKey: UUID.init().uuidString, structure: MutableStructure()) - OpenFeatureAPI.shared.setProvider(provider: provider, initialContext: ctx) + Task { + await OpenFeatureAPI.shared.setProviderAndWait(provider: provider, initialContext: ctx) + confidence.send(eventName: "my_event") + } } } diff --git a/Package.swift b/Package.swift index 7e5811ae..74afe395 100644 --- a/Package.swift +++ b/Package.swift @@ -21,6 +21,11 @@ let package = Package( .package(url: "git@github.com:open-feature/swift-sdk.git", from: "0.1.0"), ], targets: [ + .target( + name: "Confidence", + dependencies: [], + plugins: [] + ), .target( name: "ConfidenceProvider", dependencies: [ @@ -29,11 +34,6 @@ let package = Package( ], plugins: [] ), - .target( - name: "Confidence", - dependencies: [], - plugins: [] - ), .testTarget( name: "ConfidenceProviderTests", dependencies: [ diff --git a/Sources/Confidence/Confidence.swift b/Sources/Confidence/Confidence.swift index a701b5de..38408893 100644 --- a/Sources/Confidence/Confidence.swift +++ b/Sources/Confidence/Confidence.swift @@ -12,7 +12,7 @@ public class Confidence: ConfidenceEventSender { } public func send(eventName: String) { - print("Sending \(eventName)") + print("Sending \(eventName) - Targeting key: \(context["targeting_key"] ?? "UNKNOWN")") } public func updateContextEntry(key: String, value: String) { diff --git a/Sources/ConfidenceProvider/ConfidenceFeatureProvider.swift b/Sources/ConfidenceProvider/ConfidenceFeatureProvider.swift index 07f3128f..53550514 100644 --- a/Sources/ConfidenceProvider/ConfidenceFeatureProvider.swift +++ b/Sources/ConfidenceProvider/ConfidenceFeatureProvider.swift @@ -54,6 +54,7 @@ public class ConfidenceFeatureProvider: FeatureProvider { } if self.initializationStrategy == .activateAndFetchAsync { + confidence?.context = ["targeting_key": "CACHED"] eventHandler.send(.ready) } @@ -70,6 +71,7 @@ public class ConfidenceFeatureProvider: FeatureProvider { // signal the provider is ready after the network request is done if self.initializationStrategy == .fetchAndActivate { + confidence?.context = ["targeting_key": initialContext.getTargetingKey()] eventHandler.send(.ready) } } catch { @@ -111,6 +113,7 @@ public class ConfidenceFeatureProvider: FeatureProvider { // update the storage try await store(with: newContext, resolveResult: resolveResult, refreshCache: true) eventHandler.send(ProviderEvent.ready) + confidence?.context = ["targeting_key": newContext.getTargetingKey()] } catch { eventHandler.send(ProviderEvent.ready) // do nothing