// // FKRemoteConfigManager.m // FirstLink // // Created by ascii on 16/9/26. // Copyright © 2016年 FirstLink. All rights reserved. // #import "FKRemoteConfigManager.h" @interface FKRemoteConfigManager () @property (nonatomic, strong) NSString *isOpenCmbPay; @property (nonatomic, strong) NSString *isOpenRedEnvelope; @property (nonatomic, strong) NSString *isOpenOvertimeCompensate; @property (nonatomic, strong) NSString *searchBarPlaceholder; @property (nonatomic, strong) NSString *searchBarKeyword; @property (nonatomic, strong) NSString *searchTargetURL; @end @implementation FKRemoteConfigManager + (FKRemoteConfigManager *)sharedManager { static FKRemoteConfigManager *remoteConfigManagerInstance = nil; static dispatch_once_t once_token; dispatch_once(&once_token, ^{ remoteConfigManagerInstance = [[self alloc] init]; }); return remoteConfigManagerInstance; } #pragma mark - Mapping + (NSDictionary*)mts_mapping { return @{@"activity_config.open_cmb_pay": mts_key(isOpenCmbPay), @"activity_config.open_red_envelope": mts_key(isOpenRedEnvelope), @"activity_config.open_overtime_compensate": mts_key(isOpenOvertimeCompensate), @"activity_config.default_search_term.display_key": mts_key(searchBarPlaceholder), @"activity_config.default_search_term.real_key": mts_key(searchBarKeyword), @"activity_config.default_search_term.target_url": mts_key(searchTargetURL), }; } + (BOOL)mts_shouldSetUndefinedKeys { return NO; } #pragma mark - Update + (void)asyncRequsetConfig { NSString *urlString = [NSString stringWithFormat:@"%@/link-site/api/config/find_activity_config.json", [[FKServerUtil sharedInstance] apiServer]]; [[FLDataCenter sharedDataCenter] POST:urlString parameters:[FLRequestHelper commonParamater] success:^(MSGHeader *header, id responseObject) { if (header.code.intValue == RESPONSE_MSG_NORMAL) { FKRemoteConfigManager *config = [FKRemoteConfigManager sharedManager]; [config mts_setValuesForKeysWithDictionary:responseObject[@"data"]]; } } failure:^(MSGHeader *header, NSError *error) { }]; } #pragma mark - Getter + (NSString *)searchPlaceholder { FKRemoteConfigManager *config = [FKRemoteConfigManager sharedManager]; return (config.searchBarPlaceholder.length > 0 ? config.searchBarPlaceholder : @"搜索你想要的商品"); } + (NSString *)defaultSearchKeyword { FKRemoteConfigManager *config = [FKRemoteConfigManager sharedManager]; return config.searchBarKeyword; } + (NSString *)defaultSearchTargetURL { FKRemoteConfigManager *config = [FKRemoteConfigManager sharedManager]; return config.searchTargetURL; } @end