FPRRemoteConfigFlags+Private.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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/Sources/Private/FIRRemoteConfig_Private.h"
  16. NS_ASSUME_NONNULL_BEGIN
  17. static NSString *const kFPRConfigPrefix = @"com.fireperf";
  18. /** Interval at which the configurations can be fetched. Specified in seconds. */
  19. static NSInteger const kFPRConfigFetchIntervalInSeconds = 12 * 60 * 60;
  20. /** Interval after which the configurations can be fetched. Specified in seconds. */
  21. static NSInteger const kFPRConfigAppStartDelayInSeconds = 1 * 30;
  22. /** This extension should only be used for testing. */
  23. @interface FPRRemoteConfigFlags ()
  24. /** @brief Instance of remote config used for firebase performance namespace. */
  25. @property(nonatomic) FIRRemoteConfig *fprRemoteConfig;
  26. /** @brief Last activated time of the configurations. */
  27. @property(atomic) NSDate *lastFetchedTime;
  28. /** @brief User defaults used for caching. */
  29. @property(nonatomic) NSUserDefaults *userDefaults;
  30. /**
  31. * Creates an instance of FPRRemoteConfigFlags.
  32. *
  33. * @param config RemoteConfig object to be used for configuration management.
  34. * @return Instance of remote config.
  35. */
  36. - (instancetype)initWithRemoteConfig:(FIRRemoteConfig *)config NS_DESIGNATED_INITIALIZER;
  37. #pragma mark - Config fetch methods
  38. /**
  39. * Gets and returns the string value for the provided remote config flag. If there are no values
  40. * returned from remote config, default value will be returned.
  41. * @param flagName Name of the flag for which the value needs to be fetched from RC.
  42. * @param defaultValue Default value that will be returned if no value is fetched from RC.
  43. *
  44. * @return string value for the flag from RC if available. Default value, otherwise.
  45. */
  46. - (NSString *)getStringValueForFlag:(NSString *)flagName defaultValue:(NSString *)defaultValue;
  47. /**
  48. * Gets and returns the int value for the provided remote config flag. If there are no values
  49. * returned from remote config, default value will be returned.
  50. * @param flagName Name of the flag for which the value needs to be fetched from RC.
  51. * @param defaultValue Default value that will be returned if no value is fetched from RC.
  52. *
  53. * @return Int value for the flag from RC if available. Default value, otherwise.
  54. */
  55. - (int)getIntValueForFlag:(NSString *)flagName defaultValue:(int)defaultValue;
  56. /**
  57. * Gets and returns the float value for the provided remote config flag. If there are no values
  58. * returned from remote config, default value will be returned.
  59. * @param flagName Name of the flag for which the value needs to be fetched from RC.
  60. * @param defaultValue Default value that will be returned if no value is fetched from RC.
  61. *
  62. * @return Float value for the flag from RC if available. Default value, otherwise.
  63. */
  64. - (float)getFloatValueForFlag:(NSString *)flagName defaultValue:(float)defaultValue;
  65. /**
  66. * Gets and returns the boolean value for the provided remote config flag. If there are no values
  67. * returned from remote config, default value will be returned.
  68. * @param flagName Name of the flag for which the value needs to be fetched from RC.
  69. * @param defaultValue Default value that will be returned if no value is fetched from RC.
  70. *
  71. * @return Bool value for the flag from RC if available. Default value, otherwise.
  72. */
  73. - (BOOL)getBoolValueForFlag:(NSString *)flagName defaultValue:(BOOL)defaultValue;
  74. /**
  75. * Caches the remote config values.
  76. */
  77. - (void)cacheConfigValues;
  78. /**
  79. * Reset (Clears) all the remote config keys and values that were cached.
  80. */
  81. - (void)resetCache;
  82. @end
  83. NS_ASSUME_NONNULL_END