|
3 | 3 |
|
4 | 4 | import OpenFeature |
5 | 5 | import FirebaseRemoteConfig |
| 6 | +import FirebaseCore |
6 | 7 |
|
7 | 8 | public let firebaseRemoteConfigOpenFeatureProviderStaleTimeIntervalKey = "firebaseRemoteConfigOpenFeatureProviderStaleTimeIntervalKey" |
8 | 9 | public let firebaseRemoteConfigOpenFeatureProviderOldContextKey = "firebaseRemoteConfigOpenFeatureProviderOldContextKey" |
@@ -41,6 +42,7 @@ public final class FirebaseRemoteConfigOpenFeatureProvider: FeatureProvider { |
41 | 42 | public init(remoteConfig: RemoteConfigCompatible) { |
42 | 43 | self.remoteConfig = remoteConfig |
43 | 44 | updateStatus(for: remoteConfig) |
| 45 | + NotificationCenter.default.addObserver(self, selector: #selector(remoteConfigDidActivated), name: .onRemoteConfigActivated, object: nil) |
44 | 46 | } |
45 | 47 |
|
46 | 48 | public func initialize(initialContext: EvaluationContext?) { |
@@ -141,3 +143,22 @@ extension FirebaseRemoteConfigOpenFeatureProvider { |
141 | 143 | OpenFeatureAPI.shared.emitEvent(event, provider: self, error: error, details: details) |
142 | 144 | } |
143 | 145 | } |
| 146 | + |
| 147 | +extension FirebaseRemoteConfigOpenFeatureProvider { |
| 148 | + @objc func remoteConfigDidActivated(notification: Notification) { |
| 149 | + // Make sure this key is consistent with kFIRGoogleAppIDKey in FirebaseCore SDK |
| 150 | + // see also https://github.com/firebase/firebase-ios-sdk/blob/main/FirebaseRemoteConfig/Swift/PropertyWrapper/RemoteConfigValueObservable.swift |
| 151 | + let firebaseRemoteConfigAppNameKey = "FIRAppNameKey" |
| 152 | + |
| 153 | + guard let appName = notification.userInfo?[firebaseRemoteConfigAppNameKey] as? String, |
| 154 | + FirebaseApp.app()?.name == appName else { |
| 155 | + return |
| 156 | + } |
| 157 | + |
| 158 | + if status != .ready { |
| 159 | + status = .ready |
| 160 | + } |
| 161 | + |
| 162 | + emit(event: .configurationChanged) |
| 163 | + } |
| 164 | +} |
0 commit comments