Nessuna descrizione

FKRemoteConfigManager.m 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // FKRemoteConfigManager.m
  3. // FirstLink
  4. //
  5. // Created by ascii on 16/9/26.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKRemoteConfigManager.h"
  9. @interface FKRemoteConfigManager ()
  10. @property (nonatomic, strong) NSString *isOpenCmbPay;
  11. @property (nonatomic, strong) NSString *isOpenRedEnvelope;
  12. @property (nonatomic, strong) NSString *isOpenOvertimeCompensate;
  13. @property (nonatomic, strong) NSString *searchBarPlaceholder;
  14. @property (nonatomic, strong) NSString *searchBarKeyword;
  15. @property (nonatomic, strong) NSString *searchTargetURL;
  16. @end
  17. @implementation FKRemoteConfigManager
  18. + (FKRemoteConfigManager *)sharedManager {
  19. static FKRemoteConfigManager *remoteConfigManagerInstance = nil;
  20. static dispatch_once_t once_token;
  21. dispatch_once(&once_token, ^{
  22. remoteConfigManagerInstance = [[self alloc] init];
  23. });
  24. return remoteConfigManagerInstance;
  25. }
  26. #pragma mark - Mapping
  27. + (NSDictionary*)mts_mapping {
  28. return @{@"activity_config.open_cmb_pay": mts_key(isOpenCmbPay),
  29. @"activity_config.open_red_envelope": mts_key(isOpenRedEnvelope),
  30. @"activity_config.open_overtime_compensate": mts_key(isOpenOvertimeCompensate),
  31. @"activity_config.default_search_term.display_key": mts_key(searchBarPlaceholder),
  32. @"activity_config.default_search_term.real_key": mts_key(searchBarKeyword),
  33. @"activity_config.default_search_term.target_url": mts_key(searchTargetURL),
  34. };
  35. }
  36. + (BOOL)mts_shouldSetUndefinedKeys {
  37. return NO;
  38. }
  39. #pragma mark - Update
  40. + (void)asyncRequsetConfig {
  41. NSString *urlString = [NSString stringWithFormat:@"%@/link-site/api/config/find_activity_config.json", [[FKServerUtil sharedInstance] apiServer]];
  42. [[FLDataCenter sharedDataCenter] POST:urlString parameters:[FLRequestHelper commonParamater] success:^(MSGHeader *header, id responseObject) {
  43. if (header.code.intValue == RESPONSE_MSG_NORMAL) {
  44. FKRemoteConfigManager *config = [FKRemoteConfigManager sharedManager];
  45. [config mts_setValuesForKeysWithDictionary:responseObject[@"data"]];
  46. }
  47. } failure:^(MSGHeader *header, NSError *error) {
  48. }];
  49. }
  50. #pragma mark - Getter
  51. + (NSString *)searchPlaceholder {
  52. FKRemoteConfigManager *config = [FKRemoteConfigManager sharedManager];
  53. return (config.searchBarPlaceholder.length > 0 ? config.searchBarPlaceholder : @"搜索你想要的商品");
  54. }
  55. + (NSString *)defaultSearchKeyword {
  56. FKRemoteConfigManager *config = [FKRemoteConfigManager sharedManager];
  57. return config.searchBarKeyword;
  58. }
  59. + (NSString *)defaultSearchTargetURL {
  60. FKRemoteConfigManager *config = [FKRemoteConfigManager sharedManager];
  61. return config.searchTargetURL;
  62. }
  63. @end