FPRRemoteConfigFlags+Private.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // Copyright 2020 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import "FirebasePerformance/Sources/Configurations/FPRRemoteConfigFlags.h"
  15. @import FirebaseRemoteConfig;
  16. NS_ASSUME_NONNULL_BEGIN
  17. @interface FIRRemoteConfig ()
  18. + (FIRRemoteConfig *)remoteConfigWithFIRNamespace:(NSString *)remoteConfigNamespace
  19. app:(FIRApp *)app;
  20. @end
  21. @interface FIRRemoteConfigValue ()
  22. @property(nonatomic, readwrite, assign) FIRRemoteConfigSource source;
  23. /// Designated initializer.
  24. - (instancetype)initWithData:(nullable NSData *)data
  25. source:(FIRRemoteConfigSource)source NS_DESIGNATED_INITIALIZER;
  26. @end
  27. @class GULUserDefaults;
  28. static NSString *const kFPRConfigPrefix = @"com.fireperf";
  29. /** Interval at which the configurations can be fetched. Specified in seconds. */
  30. static NSInteger const kFPRConfigFetchIntervalInSeconds = 12 * 60 * 60;
  31. /** Interval after which the configurations can be fetched. Specified in seconds. */
  32. static NSInteger const kFPRMinAppStartConfigFetchDelayInSeconds = 5;
  33. /** This extension should only be used for testing. */
  34. @interface FPRRemoteConfigFlags ()
  35. /** @brief Instance of remote config used for firebase performance namespace. */
  36. @property(nonatomic) FIRRemoteConfig *fprRemoteConfig;
  37. /** @brief Last activated time of the configurations. */
  38. @property(atomic, nullable) NSDate *lastFetchedTime;
  39. /** @brief User defaults used for caching. */
  40. @property(nonatomic) GULUserDefaults *userDefaults;
  41. /** @brief Last activated time of the configurations. */
  42. @property(nonatomic) NSDate *applicationStartTime;
  43. /** @brief Number of seconds delayed until the first config is made during app start. */
  44. @property(nonatomic) NSTimeInterval appStartConfigFetchDelayInSeconds;
  45. /** @brief Status of the last remote config fetch. */
  46. @property(nonatomic) FIRRemoteConfigFetchStatus lastFetchStatus;
  47. /**
  48. * Creates an instance of FPRRemoteConfigFlags.
  49. *
  50. * @param config RemoteConfig object to be used for configuration management.
  51. * @return Instance of remote config.
  52. */
  53. - (instancetype)initWithRemoteConfig:(FIRRemoteConfig *)config NS_DESIGNATED_INITIALIZER;
  54. #pragma mark - Config fetch methods
  55. /**
  56. * Gets and returns the string value for the provided remote config flag. If there are no values
  57. * returned from remote config, default value will be returned.
  58. * @param flagName Name of the flag for which the value needs to be fetched from RC.
  59. * @param defaultValue Default value that will be returned if no value is fetched from RC.
  60. *
  61. * @return string value for the flag from RC if available. Default value, otherwise.
  62. */
  63. - (NSString *)getStringValueForFlag:(NSString *)flagName defaultValue:(NSString *)defaultValue;
  64. /**
  65. * Gets and returns the int value for the provided remote config flag. If there are no values
  66. * returned from remote config, default value will be returned.
  67. * @param flagName Name of the flag for which the value needs to be fetched from RC.
  68. * @param defaultValue Default value that will be returned if no value is fetched from RC.
  69. *
  70. * @return Int value for the flag from RC if available. Default value, otherwise.
  71. */
  72. - (int)getIntValueForFlag:(NSString *)flagName defaultValue:(int)defaultValue;
  73. /**
  74. * Gets and returns the float value for the provided remote config flag. If there are no values
  75. * returned from remote config, default value will be returned.
  76. * @param flagName Name of the flag for which the value needs to be fetched from RC.
  77. * @param defaultValue Default value that will be returned if no value is fetched from RC.
  78. *
  79. * @return Float value for the flag from RC if available. Default value, otherwise.
  80. */
  81. - (float)getFloatValueForFlag:(NSString *)flagName defaultValue:(float)defaultValue;
  82. /**
  83. * Gets and returns the boolean value for the provided remote config flag. If there are no values
  84. * returned from remote config, default value will be returned.
  85. * @param flagName Name of the flag for which the value needs to be fetched from RC.
  86. * @param defaultValue Default value that will be returned if no value is fetched from RC.
  87. *
  88. * @return Bool value for the flag from RC if available. Default value, otherwise.
  89. */
  90. - (BOOL)getBoolValueForFlag:(NSString *)flagName defaultValue:(BOOL)defaultValue;
  91. /**
  92. * Caches the remote config values.
  93. */
  94. - (void)cacheConfigValues;
  95. /**
  96. * Reset (Clears) all the remote config keys and values that were cached.
  97. */
  98. - (void)resetCache;
  99. @end
  100. NS_ASSUME_NONNULL_END