@@ -148,7 +148,7 @@ public class RemoteConfig: NSObject, NSFastEnumeration {
148148
149149 @objc public var settings : ConfigSettings
150150
151- private let configFetch : ConfigFetch
151+ let configFetch : ConfigFetch
152152
153153 private let configExperiment : ConfigExperiment
154154
@@ -201,8 +201,9 @@ public class RemoteConfig: NSObject, NSFastEnumeration {
201201 // Use the provider to generate and return instances of FIRRemoteConfig for this specific app and
202202 // namespace. This will ensure the app is configured before Remote Config can return an instance.
203203 @objc ( remoteConfigWithFIRNamespace: app: )
204- public static func remoteConfig( withFIRNamespace firebaseNamespace: String ,
205- app: FirebaseApp ) -> RemoteConfig {
204+ public static func remoteConfig( withFIRNamespace firebaseNamespace: String = RemoteConfigConstants
205+ . NamespaceGoogleMobilePlatform,
206+ app: FirebaseApp ) -> RemoteConfig {
206207 let provider = ComponentType < RemoteConfigInterop >
207208 . instance (
208209 for: RemoteConfigInterop . self,
@@ -366,10 +367,23 @@ public class RemoteConfig: NSObject, NSFastEnumeration {
366367 }
367368 }
368369
370+ /// Ensures initialization is complete and clients can begin querying for Remote Config values.
371+ @available ( iOS 13 , tvOS 13 , macOS 10 . 15 , macCatalyst 13 , watchOS 7 , * )
372+ public func ensureInitialized( ) async throws {
373+ return try await withCheckedThrowingContinuation { continuation in
374+ self . ensureInitialized { error in
375+ if let error {
376+ continuation. resume ( throwing: error)
377+ } else {
378+ continuation. resume ( )
379+ }
380+ }
381+ }
382+ }
383+
369384 /// Ensures initialization is complete and clients can begin querying for Remote Config values.
370385 /// - Parameter completionHandler: Initialization complete callback with error parameter.
371- @objc public func ensureInitialized( withCompletionHandler completionHandler: @escaping ( Error ? )
372- -> Void ) {
386+ @objc public func ensureInitialized( completionHandler: @escaping ( Error ? ) -> Void ) {
373387 DispatchQueue . global ( qos: . utility) . async { [ weak self] in
374388 guard let self = self else { return }
375389 let initializationSuccess = self . configContent. initializationSuccessful ( )
@@ -402,6 +416,27 @@ public class RemoteConfig: NSObject, NSFastEnumeration {
402416
403417 // MARK: fetch
404418
419+ /// Fetches Remote Config data with a callback. Call `activate()` to make fetched data
420+ /// available to your app.
421+ ///
422+ /// Note: This method uses a Firebase Installations token to identify the app instance, and once
423+ /// it's called, it periodically sends data to the Firebase backend. (see
424+ /// `Installations.authToken(completion:)`).
425+ /// To stop the periodic sync, call `Installations.delete(completion:)`
426+ /// and avoid calling this method again.
427+ @available ( iOS 13 , tvOS 13 , macOS 10 . 15 , macCatalyst 13 , watchOS 7 , * )
428+ public func fetch( ) async throws -> RemoteConfigFetchStatus {
429+ return try await withUnsafeThrowingContinuation ( ) { continuation in
430+ self . fetch { status, error in
431+ if let error {
432+ continuation. resume ( throwing: error)
433+ } else {
434+ continuation. resume ( returning: status)
435+ }
436+ }
437+ }
438+ }
439+
405440 /// Fetches Remote Config data with a callback. Call `activate()` to make fetched data
406441 /// available to your app.
407442 ///
@@ -419,6 +454,32 @@ public class RemoteConfig: NSObject, NSFastEnumeration {
419454 }
420455 }
421456
457+ /// Fetches Remote Config data and sets a duration that specifies how long config data lasts.
458+ /// Call `activateWithCompletion:` to make fetched data available to your app.
459+ ///
460+ /// - Parameter expirationDuration Override the (default or optionally set `minimumFetchInterval`
461+ /// property in RemoteConfigSettings) `minimumFetchInterval` for only the current request, in
462+ /// seconds. Setting a value of 0 seconds will force a fetch to the backend.
463+ ///
464+ /// Note: This method uses a Firebase Installations token to identify the app instance, and once
465+ /// it's called, it periodically sends data to the Firebase backend. (see
466+ /// `Installations.authToken(completion:)`).
467+ /// To stop the periodic sync, call `Installations.delete(completion:)`
468+ /// and avoid calling this method again.
469+ @available ( iOS 13 , tvOS 13 , macOS 10 . 15 , macCatalyst 13 , watchOS 7 , * )
470+ public func fetch( withExpirationDuration expirationDuration: TimeInterval ) async throws
471+ -> RemoteConfigFetchStatus {
472+ return try await withCheckedThrowingContinuation { continuation in
473+ self . fetch ( withExpirationDuration: expirationDuration) { status, error in
474+ if let error {
475+ continuation. resume ( throwing: error)
476+ } else {
477+ continuation. resume ( returning: status)
478+ }
479+ }
480+ }
481+ }
482+
422483 /// Fetches Remote Config data and sets a duration that specifies how long config data lasts.
423484 /// Call `activateWithCompletion:` to make fetched data available to your app.
424485 ///
@@ -440,6 +501,28 @@ public class RemoteConfig: NSObject, NSFastEnumeration {
440501
441502 // MARK: fetchAndActivate
442503
504+ /// Fetches Remote Config data and if successful, activates fetched data. Optional completion
505+ /// handler callback is invoked after the attempted activation of data, if the fetch call
506+ /// succeeded.
507+ ///
508+ /// Note: This method uses a Firebase Installations token to identify the app instance, and once
509+ /// it's called, it periodically sends data to the Firebase backend. (see
510+ /// `Installations.authToken(completion:)`).
511+ /// To stop the periodic sync, call `Installations.delete(completion:)`
512+ /// and avoid calling this method again.
513+ @available ( iOS 13 , tvOS 13 , macOS 10 . 15 , macCatalyst 13 , watchOS 7 , * )
514+ public func fetchAndActivate( ) async throws -> RemoteConfigFetchAndActivateStatus {
515+ return try await withCheckedThrowingContinuation { continuation in
516+ self . fetchAndActivate { status, error in
517+ if let error {
518+ continuation. resume ( throwing: error)
519+ } else {
520+ continuation. resume ( returning: status)
521+ }
522+ }
523+ }
524+ }
525+
443526 /// Fetches Remote Config data and if successful, activates fetched data. Optional completion
444527 /// handler callback is invoked after the attempted activation of data, if the fetch call
445528 /// succeeded.
@@ -451,8 +534,9 @@ public class RemoteConfig: NSObject, NSFastEnumeration {
451534 /// and avoid calling this method again.
452535 ///
453536 /// - Parameter completionHandler Fetch operation callback with status and error parameters.
454- @objc public func fetchAndActivate( withCompletionHandler completionHandler:
455- @escaping ( RemoteConfigFetchAndActivateStatus , Error ? ) -> Void ) {
537+ @objc public func fetchAndActivate( completionHandler:
538+ ( ( RemoteConfigFetchAndActivateStatus , Error ? ) -> Void ) ? =
539+ nil ) {
456540 fetch { [ weak self] status, error in
457541 guard let self = self else { return }
458542 // Fetch completed. We are being called on the main queue.
@@ -461,11 +545,13 @@ public class RemoteConfig: NSObject, NSFastEnumeration {
461545 self . activate { changed, error in
462546 let status : RemoteConfigFetchAndActivateStatus = error == nil ?
463547 . successFetchedFromRemote : . successUsingPreFetchedData
464- DispatchQueue . main. async {
465- completionHandler ( status, nil )
548+ if let completionHandler {
549+ DispatchQueue . main. async {
550+ completionHandler ( status, nil )
551+ }
466552 }
467553 }
468- } else {
554+ } else if let completionHandler {
469555 DispatchQueue . main. async {
470556 completionHandler ( . error, error)
471557 }
@@ -475,10 +561,26 @@ public class RemoteConfig: NSObject, NSFastEnumeration {
475561
476562 // MARK: activate
477563
564+ /// Applies Fetched Config data to the Active Config, causing updates to the behavior and
565+ /// appearance of the app to take effect (depending on how config data is used in the app).
566+ /// - Returns A Bool indicating whether or not a change occurred.
567+ @available ( iOS 13 , tvOS 13 , macOS 10 . 15 , macCatalyst 13 , watchOS 7 , * )
568+ public func activate( ) async throws -> Bool {
569+ return try await withCheckedThrowingContinuation { continuation in
570+ self . activate { updated, error in
571+ if let error {
572+ continuation. resume ( throwing: error)
573+ } else {
574+ continuation. resume ( returning: updated)
575+ }
576+ }
577+ }
578+ }
579+
478580 /// Applies Fetched Config data to the Active Config, causing updates to the behavior and
479581 /// appearance of the app to take effect (depending on how config data is used in the app).
480582 /// - Parameter completion Activate operation callback with changed and error parameters.
481- @objc public func activate( withCompletion completion: ( ( Bool , Error ? ) -> Void ) ? ) {
583+ @objc public func activate( completion: ( ( Bool , Error ? ) -> Void ) ? = nil ) {
482584 queue. async { [ weak self] in
483585 guard let self = self else {
484586 let error = NSError (
@@ -759,8 +861,9 @@ public class RemoteConfig: NSObject, NSFastEnumeration {
759861 /// - Returns Returns a registration representing the listener. The registration
760862 /// contains a remove method, which can be used to stop receiving updates for the provided
761863 /// listener.
762- @objc public func addOnConfigUpdateListener( _ listener: @Sendable @escaping ( RemoteConfigUpdate ? ,
763- Error ? ) -> Void )
864+ @objc public func addOnConfigUpdateListener( remoteConfigUpdateCompletion listener: @Sendable @escaping ( RemoteConfigUpdate ? ,
865+ Error ? )
866+ -> Void )
764867 -> ConfigUpdateListenerRegistration {
765868 return configRealtime. addConfigUpdateListener ( listener)
766869 }
0 commit comments