UMRemoteConfig.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //
  2. // UMRemoteConfig.h
  3. // myFireBase
  4. //
  5. // Created by 张军华 on 2019/12/30.
  6. // Copyright © 2019年 张军华. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import "UMRemoteConfigEnum.h"
  10. NS_ASSUME_NONNULL_BEGIN
  11. typedef void (^UMRemoteConfigFetchCompletion)(UMRemoteConfigFetchStatus status,
  12. NSError *_Nullable error);
  13. typedef void (^UMRemoteConfigActivateCompletion)(NSError *_Nullable error);
  14. @protocol UMRemoteConfigDelegate<NSObject>
  15. @optional
  16. /**
  17. * @brief 获取服务器的网络请求的回调
  18. * @param status see UMRemoteConfigFetchStatus
  19. * @param error 错误信息
  20. * @param userInfo 该回调的扩展信息
  21. * @note 调用函数触发此回调
  22. * fetchWithCompletionHandler
  23. * fetchAndActivateWithCompletionHandler
  24. */
  25. -(void)remoteConfigFetched:(UMRemoteConfigFetchStatus)status
  26. error:(nullable NSError*)error
  27. userInfo:(nullable id)userInfo;
  28. /**
  29. * @brief 远程配置被激活的回调
  30. * @param status see UMRemoteConfigActiveStatus
  31. * @param error 错误信息
  32. * @param userInfo 该回调的扩展信息
  33. * @note 调用函数触发此回调
  34. * fetchAndActivateWithCompletionHandler
  35. * activateWithCompletionHandler
  36. */
  37. -(void)remoteConfigActivated:(UMRemoteConfigActiveStatus)status
  38. error:(nullable NSError*)error
  39. userInfo:(nullable id)userInfo;
  40. /**
  41. * @brief 配置已经准备就绪
  42. * @param status see UMRemoteConfigActiveStatus
  43. * @param error 错误信息
  44. * @param userInfo 该回调的扩展信息
  45. * @note 调用函数触发此回调
  46. * fetchWithCompletionHandler
  47. */
  48. -(void)remoteConfigReady:(UMRemoteConfigActiveStatus)status
  49. error:(nullable NSError*)error
  50. userInfo:(nullable id)userInfo;
  51. @end
  52. @class UMRemoteConfigSettings;
  53. @interface UMRemoteConfig : NSObject
  54. @property(nonatomic,assign)id<UMRemoteConfigDelegate> remoteConfigDelegate;
  55. @property(nonatomic, readwrite, strong) UMRemoteConfigSettings *configSettings;
  56. #pragma mark - init
  57. /**
  58. * @brief 远程配置单例
  59. * @param delegate see UMRemoteConfigDelegate
  60. * @note 用户初始化时候,
  61. 先调用 remoteConfigWithDelegate:(id<UMRemoteConfigDelegate>)delegate,可以保证上次ready的数据可以回调给用户。
  62. */
  63. + (UMRemoteConfig *)remoteConfigWithDelegate:(nullable id<UMRemoteConfigDelegate>)delegate
  64. withConfigSettings:(nullable UMRemoteConfigSettings*)configSettings;
  65. + (UMRemoteConfig *)remoteConfig;
  66. #pragma mark - activate
  67. /**
  68. * @brief 激活本地配置
  69. * @param completionHandler 回调
  70. */
  71. + (void)activateWithCompletionHandler:(nullable UMRemoteConfigActivateCompletion)completionHandler;
  72. #pragma mark - Get Config
  73. /**
  74. * @brief 获取配置信息
  75. * @param key 对应的key
  76. * @note 获取配置的有限顺利,远程配置->Defaults
  77. */
  78. + (nullable id)configValueForKey:(nullable NSString *)key;
  79. #pragma mark - Defaults
  80. /**
  81. * @brief 设置本地默认配置
  82. * @param defaults 对应的本地配置
  83. */
  84. + (void)setDefaults:(nullable NSDictionary<NSString *, NSObject *> *)defaults;
  85. /**
  86. * @brief 设置本地默认配置
  87. * @param fileName 包含本地配置的plist文件
  88. */
  89. + (void)setDefaultsFromPlistFileName:(nullable NSString *)fileName;
  90. @end
  91. NS_ASSUME_NONNULL_END