FIRRemoteConfig.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. /*
  2. * Copyright 2019 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. @class FIRApp;
  18. /// The Firebase Remote Config service default namespace, to be used if the API method does not
  19. /// specify a different namespace. Use the default namespace if configuring from the Google Firebase
  20. /// service.
  21. extern NSString *const _Nonnull FIRNamespaceGoogleMobilePlatform NS_SWIFT_NAME(
  22. NamespaceGoogleMobilePlatform);
  23. /// Key used to manage throttling in NSError user info when the refreshing of Remote Config
  24. /// parameter values (data) is throttled. The value of this key is the elapsed time since 1970,
  25. /// measured in seconds.
  26. extern NSString *const _Nonnull FIRRemoteConfigThrottledEndTimeInSecondsKey NS_SWIFT_NAME(
  27. RemoteConfigThrottledEndTimeInSecondsKey);
  28. /**
  29. * Listener registration returned by `addOnConfigUpdateListener`. Calling its method `remove` stops
  30. * the associated listener from receiving config updates and unregisters itself.
  31. *
  32. * If remove is called and no other listener registrations remain, the connection to the real-time
  33. * RC backend is closed. Subsequently calling `addOnConfigUpdateListener` will re-open the
  34. * connection.
  35. */
  36. NS_SWIFT_SENDABLE
  37. NS_SWIFT_NAME(ConfigUpdateListenerRegistration)
  38. @interface FIRConfigUpdateListenerRegistration : NSObject
  39. /**
  40. * Removes the listener associated with this `ConfigUpdateListenerRegistration`. After the
  41. * initial call, subsequent calls have no effect.
  42. */
  43. - (void)remove;
  44. @end
  45. /// Indicates whether updated data was successfully fetched.
  46. typedef NS_ENUM(NSInteger, FIRRemoteConfigFetchStatus) {
  47. /// Config has never been fetched.
  48. FIRRemoteConfigFetchStatusNoFetchYet,
  49. /// Config fetch succeeded.
  50. FIRRemoteConfigFetchStatusSuccess,
  51. /// Config fetch failed.
  52. FIRRemoteConfigFetchStatusFailure,
  53. /// Config fetch was throttled.
  54. FIRRemoteConfigFetchStatusThrottled,
  55. } NS_SWIFT_NAME(RemoteConfigFetchStatus);
  56. /// Indicates whether updated data was successfully fetched and activated.
  57. typedef NS_ENUM(NSInteger, FIRRemoteConfigFetchAndActivateStatus) {
  58. /// The remote fetch succeeded and fetched data was activated.
  59. FIRRemoteConfigFetchAndActivateStatusSuccessFetchedFromRemote,
  60. /// The fetch and activate succeeded from already fetched but yet unexpired config data. You can
  61. /// control this using minimumFetchInterval property in FIRRemoteConfigSettings.
  62. FIRRemoteConfigFetchAndActivateStatusSuccessUsingPreFetchedData,
  63. /// The fetch and activate failed.
  64. FIRRemoteConfigFetchAndActivateStatusError
  65. } NS_SWIFT_NAME(RemoteConfigFetchAndActivateStatus);
  66. /// Remote Config error domain that handles errors when fetching data from the service.
  67. extern NSString *const _Nonnull FIRRemoteConfigErrorDomain NS_SWIFT_NAME(RemoteConfigErrorDomain);
  68. /// Firebase Remote Config service fetch error.
  69. typedef NS_ERROR_ENUM(FIRRemoteConfigErrorDomain, FIRRemoteConfigError){
  70. /// Unknown or no error.
  71. FIRRemoteConfigErrorUnknown = 8001,
  72. /// Frequency of fetch requests exceeds throttled limit.
  73. FIRRemoteConfigErrorThrottled = 8002,
  74. /// Internal error that covers all internal HTTP errors.
  75. FIRRemoteConfigErrorInternalError = 8003,
  76. } NS_SWIFT_NAME(RemoteConfigError);
  77. /// Remote Config error domain that handles errors for the real-time config update service.
  78. extern NSString *const _Nonnull FIRRemoteConfigUpdateErrorDomain NS_SWIFT_NAME(RemoteConfigUpdateErrorDomain);
  79. /// Firebase Remote Config real-time config update service error.
  80. typedef NS_ERROR_ENUM(FIRRemoteConfigUpdateErrorDomain, FIRRemoteConfigUpdateError){
  81. /// Unable to make a connection to the Remote Config backend.
  82. FIRRemoteConfigUpdateErrorStreamError = 8001,
  83. /// Unable to fetch the latest version of the config.
  84. FIRRemoteConfigUpdateErrorNotFetched = 8002,
  85. /// The ConfigUpdate message was unparsable.
  86. FIRRemoteConfigUpdateErrorMessageInvalid = 8003,
  87. /// The Remote Config real-time config update service is unavailable.
  88. FIRRemoteConfigUpdateErrorUnavailable = 8004,
  89. } NS_SWIFT_NAME(RemoteConfigUpdateError);
  90. /// Error domain for custom signals errors.
  91. extern NSString *const _Nonnull FIRRemoteConfigCustomSignalsErrorDomain NS_SWIFT_NAME(RemoteConfigCustomSignalsErrorDomain);
  92. /// Firebase Remote Config custom signals error.
  93. typedef NS_ERROR_ENUM(FIRRemoteConfigCustomSignalsErrorDomain, FIRRemoteConfigCustomSignalsError){
  94. /// Unknown error.
  95. FIRRemoteConfigCustomSignalsErrorUnknown = 8101,
  96. /// Invalid value type in the custom signals dictionary.
  97. FIRRemoteConfigCustomSignalsErrorInvalidValueType = 8102,
  98. /// Limit exceeded for key length, value length, or number of signals.
  99. FIRRemoteConfigCustomSignalsErrorLimitExceeded = 8103,
  100. } NS_SWIFT_NAME(RemoteConfigCustomSignalsError);
  101. /// Enumerated value that indicates the source of Remote Config data. Data can come from
  102. /// the Remote Config service, the DefaultConfig that is available when the app is first installed,
  103. /// or a static initialized value if data is not available from the service or DefaultConfig.
  104. typedef NS_ENUM(NSInteger, FIRRemoteConfigSource) {
  105. FIRRemoteConfigSourceRemote, ///< The data source is the Remote Config service.
  106. FIRRemoteConfigSourceDefault, ///< The data source is the DefaultConfig defined for this app.
  107. FIRRemoteConfigSourceStatic, ///< The data doesn't exist, return a static initialized value.
  108. } NS_SWIFT_NAME(RemoteConfigSource);
  109. /// Completion handler invoked by fetch methods when they get a response from the server.
  110. ///
  111. /// @param status Config fetching status.
  112. /// @param error Error message on failure.
  113. typedef void (^FIRRemoteConfigFetchCompletion)(FIRRemoteConfigFetchStatus status,
  114. NSError *_Nullable error)
  115. NS_SWIFT_UNAVAILABLE("Use Swift's closure syntax instead.");
  116. /// Completion handler invoked by activate method upon completion.
  117. /// @param error Error message on failure. Nil if activation was successful.
  118. typedef void (^FIRRemoteConfigActivateCompletion)(NSError *_Nullable error)
  119. NS_SWIFT_UNAVAILABLE("Use Swift's closure syntax instead.");
  120. /// Completion handler invoked upon completion of Remote Config initialization.
  121. ///
  122. /// @param initializationError nil if initialization succeeded.
  123. typedef void (^FIRRemoteConfigInitializationCompletion)(NSError *_Nullable initializationError)
  124. NS_SWIFT_UNAVAILABLE("Use Swift's closure syntax instead.");
  125. /// Completion handler invoked by the fetchAndActivate method. Used to convey status of fetch and,
  126. /// if successful, resultant activate call
  127. /// @param status Config fetching status.
  128. /// @param error Error message on failure of config fetch
  129. typedef void (^FIRRemoteConfigFetchAndActivateCompletion)(
  130. FIRRemoteConfigFetchAndActivateStatus status, NSError *_Nullable error)
  131. NS_SWIFT_UNAVAILABLE("Use Swift's closure syntax instead.");
  132. #pragma mark - FIRRemoteConfigValue
  133. /// This class provides a wrapper for Remote Config parameter values, with methods to get parameter
  134. /// values as different data types.
  135. NS_SWIFT_NAME(RemoteConfigValue)
  136. @interface FIRRemoteConfigValue : NSObject <NSCopying>
  137. /// Gets the value as a string.
  138. @property(nonatomic, readonly, nonnull) NSString *stringValue;
  139. /// Gets the value as a number value.
  140. @property(nonatomic, readonly, nonnull) NSNumber *numberValue;
  141. /// Gets the value as a NSData object.
  142. @property(nonatomic, readonly, nonnull) NSData *dataValue;
  143. /// Gets the value as a boolean.
  144. @property(nonatomic, readonly) BOOL boolValue;
  145. /// Gets a foundation object (NSDictionary / NSArray) by parsing the value as JSON. This method uses
  146. /// NSJSONSerialization's JSONObjectWithData method with an options value of 0.
  147. @property(nonatomic, readonly, nullable) id JSONValue NS_SWIFT_NAME(jsonValue);
  148. /// Identifies the source of the fetched value.
  149. @property(nonatomic, readonly) FIRRemoteConfigSource source;
  150. @end
  151. #pragma mark - FIRRemoteConfigSettings
  152. /// Firebase Remote Config settings.
  153. NS_SWIFT_NAME(RemoteConfigSettings)
  154. @interface FIRRemoteConfigSettings : NSObject
  155. /// Indicates the default value in seconds to set for the minimum interval that needs to elapse
  156. /// before a fetch request can again be made to the Remote Config backend. After a fetch request to
  157. /// the backend has succeeded, no additional fetch requests to the backend will be allowed until the
  158. /// minimum fetch interval expires. Note that you can override this default on a per-fetch request
  159. /// basis using `RemoteConfig.fetch(withExpirationDuration:)`. For example, setting
  160. /// the expiration duration to 0 in the fetch request will override the `minimumFetchInterval` and
  161. /// allow the request to proceed.
  162. @property(nonatomic, assign) NSTimeInterval minimumFetchInterval;
  163. /// Indicates the default value in seconds to abandon a pending fetch request made to the backend.
  164. /// This value is set for outgoing requests as the `timeoutIntervalForRequest` as well as the
  165. /// `timeoutIntervalForResource` on the `NSURLSession`'s configuration.
  166. @property(nonatomic, assign) NSTimeInterval fetchTimeout;
  167. @end
  168. #pragma mark - FIRRemoteConfigUpdate
  169. /// Used by Remote Config real-time config update service, this class represents changes between the
  170. /// newly fetched config and the current one. An instance of this class is passed to
  171. /// `FIRRemoteConfigUpdateCompletion` when a new config version has been automatically fetched.
  172. NS_SWIFT_NAME(RemoteConfigUpdate)
  173. @interface FIRRemoteConfigUpdate : NSObject
  174. /// Parameter keys whose values have been updated from the currently activated values. Includes
  175. /// keys that are added, deleted, and whose value, value source, or metadata has changed.
  176. @property(nonatomic, readonly, nonnull) NSSet<NSString *> *updatedKeys;
  177. @end
  178. #pragma mark - FIRRemoteConfig
  179. /// Firebase Remote Config class. The class method `remoteConfig()` can be used
  180. /// to fetch, activate and read config results and set default config results on the default
  181. /// Remote Config instance.
  182. NS_SWIFT_NAME(RemoteConfig)
  183. @interface FIRRemoteConfig : NSObject <NSFastEnumeration>
  184. /// Last successful fetch completion time.
  185. @property(nonatomic, readonly, strong, nullable) NSDate *lastFetchTime;
  186. /// Last fetch status. The status can be any enumerated value from `RemoteConfigFetchStatus`.
  187. @property(nonatomic, readonly, assign) FIRRemoteConfigFetchStatus lastFetchStatus;
  188. /// Config settings are custom settings.
  189. @property(nonatomic, readwrite, strong, nonnull) FIRRemoteConfigSettings *configSettings;
  190. /// Returns the `RemoteConfig` instance configured for the default Firebase app. This singleton
  191. /// object contains the complete set of Remote Config parameter values available to the app,
  192. /// including the Active Config and Default Config. This object also caches values fetched from the
  193. /// Remote Config server until they are copied to the Active Config by calling `activate()`. When
  194. /// you fetch values from the Remote Config server using the default Firebase app, you should use
  195. /// this class method to create and reuse a shared instance of `RemoteConfig`.
  196. + (nonnull FIRRemoteConfig *)remoteConfig NS_SWIFT_NAME(remoteConfig());
  197. /// Returns the `RemoteConfig` instance for your (non-default) Firebase appID. Note that Firebase
  198. /// analytics does not work for non-default app instances. This singleton object contains the
  199. /// complete set of Remote Config parameter values available to the app, including the Active Config
  200. /// and Default Config. This object also caches values fetched from the Remote Config Server until
  201. /// they are copied to the Active Config by calling `activate())`. When you fetch values
  202. /// from the Remote Config Server using the non-default Firebase app, you should use this
  203. /// class method to create and reuse shared instance of `RemoteConfig`.
  204. + (nonnull FIRRemoteConfig *)remoteConfigWithApp:(nonnull FIRApp *)app
  205. NS_SWIFT_NAME(remoteConfig(app:));
  206. /// Unavailable. Use +remoteConfig instead.
  207. - (nonnull instancetype)init __attribute__((unavailable("Use +remoteConfig instead.")));
  208. #if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 180000)
  209. /// Ensures initialization is complete and clients can begin querying for Remote Config values.
  210. /// @param completionHandler Initialization complete callback with error parameter.
  211. - (void)ensureInitializedWithCompletionHandler:
  212. (void (^_Nonnull NS_SWIFT_SENDABLE)(NSError *_Nullable initializationError))completionHandler;
  213. #else
  214. /// Ensures initialization is complete and clients can begin querying for Remote Config values.
  215. /// @param completionHandler Initialization complete callback with error parameter.
  216. - (void)ensureInitializedWithCompletionHandler:
  217. (void (^_Nonnull)(NSError *_Nullable initializationError))completionHandler;
  218. #endif
  219. #pragma mark - Fetch
  220. #if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 180000)
  221. /// Fetches Remote Config data with a callback. Call `activate()` to make fetched data
  222. /// available to your app.
  223. ///
  224. /// Note: This method uses a Firebase Installations token to identify the app instance, and once
  225. /// it's called, it periodically sends data to the Firebase backend. (see
  226. /// `Installations.authToken(completion:)`).
  227. /// To stop the periodic sync, call `Installations.delete(completion:)`
  228. /// and avoid calling this method again.
  229. ///
  230. /// @param completionHandler Fetch operation callback with status and error parameters.
  231. - (void)fetchWithCompletionHandler:
  232. (void (^_Nullable NS_SWIFT_SENDABLE)(FIRRemoteConfigFetchStatus status,
  233. NSError *_Nullable error))completionHandler;
  234. #else
  235. /// Fetches Remote Config data with a callback. Call `activate()` to make fetched data
  236. /// available to your app.
  237. ///
  238. /// Note: This method uses a Firebase Installations token to identify the app instance, and once
  239. /// it's called, it periodically sends data to the Firebase backend. (see
  240. /// `Installations.authToken(completion:)`).
  241. /// To stop the periodic sync, call `Installations.delete(completion:)`
  242. /// and avoid calling this method again.
  243. ///
  244. /// @param completionHandler Fetch operation callback with status and error parameters.
  245. - (void)fetchWithCompletionHandler:(void (^_Nullable)(FIRRemoteConfigFetchStatus status,
  246. NSError *_Nullable error))completionHandler;
  247. #endif
  248. #if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 180000)
  249. /// Fetches Remote Config data and sets a duration that specifies how long config data lasts.
  250. /// Call `activateWithCompletion:` to make fetched data available to your app.
  251. ///
  252. /// Note: This method uses a Firebase Installations token to identify the app instance, and once
  253. /// it's called, it periodically sends data to the Firebase backend. (see
  254. /// `Installations.authToken(completion:)`).
  255. /// To stop the periodic sync, call `Installations.delete(completion:)`
  256. /// and avoid calling this method again.
  257. ///
  258. /// @param expirationDuration Override the (default or optionally set `minimumFetchInterval`
  259. /// property in RemoteConfigSettings) `minimumFetchInterval` for only the current request, in
  260. /// seconds. Setting a value of 0 seconds will force a fetch to the backend.
  261. /// @param completionHandler Fetch operation callback with status and error parameters.
  262. - (void)fetchWithExpirationDuration:(NSTimeInterval)expirationDuration
  263. completionHandler:(void (^_Nullable NS_SWIFT_SENDABLE)(
  264. FIRRemoteConfigFetchStatus status,
  265. NSError *_Nullable error))completionHandler;
  266. #else
  267. /// Fetches Remote Config data and sets a duration that specifies how long config data lasts.
  268. /// Call `activateWithCompletion:` to make fetched data available to your app.
  269. ///
  270. /// Note: This method uses a Firebase Installations token to identify the app instance, and once
  271. /// it's called, it periodically sends data to the Firebase backend. (see
  272. /// `Installations.authToken(completion:)`).
  273. /// To stop the periodic sync, call `Installations.delete(completion:)`
  274. /// and avoid calling this method again.
  275. ///
  276. /// @param expirationDuration Override the (default or optionally set `minimumFetchInterval`
  277. /// property in RemoteConfigSettings) `minimumFetchInterval` for only the current request, in
  278. /// seconds. Setting a value of 0 seconds will force a fetch to the backend.
  279. /// @param completionHandler Fetch operation callback with status and error parameters.
  280. - (void)fetchWithExpirationDuration:(NSTimeInterval)expirationDuration
  281. completionHandler:(void (^_Nullable)(FIRRemoteConfigFetchStatus status,
  282. NSError *_Nullable error))completionHandler;
  283. #endif
  284. #if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 180000)
  285. /// Fetches Remote Config data and if successful, activates fetched data. Optional completion
  286. /// handler callback is invoked after the attempted activation of data, if the fetch call succeeded.
  287. ///
  288. /// Note: This method uses a Firebase Installations token to identify the app instance, and once
  289. /// it's called, it periodically sends data to the Firebase backend. (see
  290. /// `Installations.authToken(completion:)`).
  291. /// To stop the periodic sync, call `Installations.delete(completion:)`
  292. /// and avoid calling this method again.
  293. ///
  294. /// @param completionHandler Fetch operation callback with status and error parameters.
  295. - (void)fetchAndActivateWithCompletionHandler:
  296. (void (^_Nullable NS_SWIFT_SENDABLE)(FIRRemoteConfigFetchAndActivateStatus status,
  297. NSError *_Nullable error))completionHandler;
  298. #else
  299. /// Fetches Remote Config data and if successful, activates fetched data. Optional completion
  300. /// handler callback is invoked after the attempted activation of data, if the fetch call succeeded.
  301. ///
  302. /// Note: This method uses a Firebase Installations token to identify the app instance, and once
  303. /// it's called, it periodically sends data to the Firebase backend. (see
  304. /// `Installations.authToken(completion:)`).
  305. /// To stop the periodic sync, call `Installations.delete(completion:)`
  306. /// and avoid calling this method again.
  307. ///
  308. /// @param completionHandler Fetch operation callback with status and error parameters.
  309. - (void)fetchAndActivateWithCompletionHandler:
  310. (void (^_Nullable)(FIRRemoteConfigFetchAndActivateStatus status,
  311. NSError *_Nullable error))completionHandler;
  312. #endif
  313. #pragma mark - Apply
  314. #if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 180000)
  315. /// Applies Fetched Config data to the Active Config, causing updates to the behavior and appearance
  316. /// of the app to take effect (depending on how config data is used in the app).
  317. /// @param completion Activate operation callback with changed and error parameters.
  318. - (void)activateWithCompletion:
  319. (void (^_Nullable NS_SWIFT_SENDABLE)(BOOL changed, NSError *_Nullable error))completion;
  320. #else
  321. /// Applies Fetched Config data to the Active Config, causing updates to the behavior and appearance
  322. /// of the app to take effect (depending on how config data is used in the app).
  323. /// @param completion Activate operation callback with changed and error parameters.
  324. - (void)activateWithCompletion:(void (^_Nullable)(BOOL changed,
  325. NSError *_Nullable error))completion;
  326. #endif
  327. #pragma mark - Get Config
  328. /// Enables access to configuration values by using object subscripting syntax.
  329. /// For example:
  330. /// let config = RemoteConfig.remoteConfig()
  331. /// let value = config["yourKey"]
  332. /// let boolValue = value.boolValue
  333. /// let number = config["yourKey"].numberValue
  334. - (nonnull FIRRemoteConfigValue *)objectForKeyedSubscript:(nonnull NSString *)key;
  335. /// Gets the config value.
  336. /// @param key Config key.
  337. - (nonnull FIRRemoteConfigValue *)configValueForKey:(nullable NSString *)key;
  338. /// Gets the config value of a given source from the default namespace.
  339. /// @param key Config key.
  340. /// @param source Config value source.
  341. - (nonnull FIRRemoteConfigValue *)configValueForKey:(nullable NSString *)key
  342. source:(FIRRemoteConfigSource)source;
  343. /// Gets all the parameter keys of a given source from the default namespace.
  344. ///
  345. /// @param source The config data source.
  346. /// @return An array of keys under the given source.
  347. - (nonnull NSArray<NSString *> *)allKeysFromSource:(FIRRemoteConfigSource)source;
  348. /// Returns the set of parameter keys that start with the given prefix, from the default namespace
  349. /// in the active config.
  350. ///
  351. /// @param prefix The key prefix to look for. If prefix is nil or empty, returns all the
  352. /// keys.
  353. /// @return The set of parameter keys that start with the specified prefix.
  354. - (nonnull NSSet<NSString *> *)keysWithPrefix:(nullable NSString *)prefix;
  355. #pragma mark - Defaults
  356. /// Sets config defaults for parameter keys and values in the default namespace config.
  357. /// @param defaults A dictionary mapping a NSString * key to a NSObject * value.
  358. - (void)setDefaults:(nullable NSDictionary<NSString *, NSObject *> *)defaults;
  359. /// Sets default configs from plist for default namespace.
  360. ///
  361. /// @param fileName The plist file name, with no file name extension. For example, if the plist file
  362. /// is named `defaultSamples.plist`:
  363. /// `RemoteConfig.remoteConfig().setDefaults(fromPlist: "defaultSamples")`
  364. - (void)setDefaultsFromPlistFileName:(nullable NSString *)fileName
  365. NS_SWIFT_NAME(setDefaults(fromPlist:));
  366. /// Returns the default value of a given key from the default config.
  367. ///
  368. /// @param key The parameter key of default config.
  369. /// @return Returns the default value of the specified key. Returns
  370. /// nil if the key doesn't exist in the default config.
  371. - (nullable FIRRemoteConfigValue *)defaultValueForKey:(nullable NSString *)key;
  372. #pragma mark - Real-time Config Updates
  373. /// Completion handler invoked by `addOnConfigUpdateListener` when there is an update to
  374. /// the config from the backend.
  375. ///
  376. /// @param configUpdate An instance of `FIRRemoteConfigUpdate` that contains information on which
  377. /// key's values have changed.
  378. /// @param error Error message on failure.
  379. typedef void (^FIRRemoteConfigUpdateCompletion)(FIRRemoteConfigUpdate *_Nullable configUpdate,
  380. NSError *_Nullable error)
  381. NS_SWIFT_UNAVAILABLE("Use Swift's closure syntax instead.");
  382. #if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 180000)
  383. /// Start listening for real-time config updates from the Remote Config backend and automatically
  384. /// fetch updates when they're available.
  385. ///
  386. /// If a connection to the Remote Config backend is not already open, calling this method will
  387. /// open it. Multiple listeners can be added by calling this method again, but subsequent calls
  388. /// re-use the same connection to the backend.
  389. ///
  390. /// Note: Real-time Remote Config requires the Firebase Remote Config Realtime API. See Get started
  391. /// with Firebase Remote Config at https://firebase.google.com/docs/remote-config/get-started for
  392. /// more information.
  393. ///
  394. /// @param listener The configured listener that is called for every config update.
  395. /// @return Returns a registration representing the listener. The registration contains
  396. /// a remove method, which can be used to stop receiving updates for the provided listener.
  397. - (FIRConfigUpdateListenerRegistration *_Nonnull)addOnConfigUpdateListener:
  398. (FIRRemoteConfigUpdateCompletion _Nonnull NS_SWIFT_SENDABLE)listener
  399. NS_SWIFT_NAME(addOnConfigUpdateListener(remoteConfigUpdateCompletion:));
  400. #else
  401. /// Start listening for real-time config updates from the Remote Config backend and automatically
  402. /// fetch updates when they're available.
  403. ///
  404. /// If a connection to the Remote Config backend is not already open, calling this method will
  405. /// open it. Multiple listeners can be added by calling this method again, but subsequent calls
  406. /// re-use the same connection to the backend.
  407. ///
  408. /// Note: Real-time Remote Config requires the Firebase Remote Config Realtime API. See Get started
  409. /// with Firebase Remote Config at https://firebase.google.com/docs/remote-config/get-started for
  410. /// more information.
  411. ///
  412. /// @param listener The configured listener that is called for every config update.
  413. /// @return Returns a registration representing the listener. The registration contains
  414. /// a remove method, which can be used to stop receiving updates for the provided listener.
  415. - (FIRConfigUpdateListenerRegistration *_Nonnull)addOnConfigUpdateListener:
  416. (FIRRemoteConfigUpdateCompletion _Nonnull)listener
  417. NS_SWIFT_NAME(addOnConfigUpdateListener(remoteConfigUpdateCompletion:));
  418. #endif
  419. - (void)setCustomSignals:(nonnull NSDictionary<NSString *, NSObject *> *)customSignals
  420. withCompletion:(void (^_Nullable)(NSError *_Nullable error))completionHandler
  421. NS_REFINED_FOR_SWIFT;
  422. @end