Firebase缓存过期始终与调试模式一样

Tat*_*yak 6 objective-c ios firebase firebase-remote-config

我正在尝试在我的iOS应用中实施Firebase远程配置.一切正常,但有一个问题 - 远程配置总是从firebase服务器获取数据,而不是从缓存中获取数据.我尝试过很多变种而没有任何成功.这是我的代码:

+ (instancetype)sharedInstance
{
static ConfigManager *_sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
    _sharedInstance = [[self alloc] init];

});
return _sharedInstance;
}

-(instancetype)init
{
self = [super init];
if (self) {
    self.remoteConfig = [FIRRemoteConfig remoteConfig];
    [self updateRemoteConfig];
}
return self;
} 

- (void)activateDebugMode
{
FIRRemoteConfigSettings *remoteConfigSettings = [[FIRRemoteConfigSettings alloc] initWithDeveloperModeEnabled:YES];
self.remoteConfig.configSettings = remoteConfigSettings;
}

- (void)updateRemoteConfig
{
[self fetchConfigWithCompletionHandler:nil];
}

- (void)fetchConfigWithCompletionHandler:  (FireBaseConfigCompletionHandler)completionHandler
{
NSTimeInterval cacheExpiration = 43200;
BOOL debug = ConfigurationValue(DebugMode);
if (debug) {
    cacheExpiration = 0;
    [self activateDebugMode];
}

[self.remoteConfig fetchWithExpirationDuration:cacheExpiration completionHandler:^(FIRRemoteConfigFetchStatus status, NSError * _Nullable error) {
    if (status == FIRRemoteConfigFetchStatusSuccess) {
        NSLog(@"Config fetched!");
        [self.remoteConfig activateFetched];
        // do smth
    } else {
        NSLog(@"Config not fetched");
        NSLog(@"Error %@", error.localizedDescription);
    }
}];
}
Run Code Online (Sandbox Code Playgroud)

即使我使用fetchWithCompletionHandler而没有cacheExpriration参数,它也不起作用.在debugMode = FALSE中设置remoteConfigSettings也不起作用.我用相同的代码创建了一个小测试应用程序,它的工作原理!我能看到的唯一区别是内置设置中的"启用模块"参数.我究竟做错了什么?先感谢您!

May*_*ain 0

抱歉,我不知道如何阅读 Objective C 代码 - 但看起来当您的应用程序在调试模式下运行时,您将 cacheExpiration 设置为 0。

当cacheExpiration为0时,所有请求都会命中网络。这旨在帮助本地开发工作流程。我建议使用更大的 cacheExpiration 值重试此代码

请参阅https://firebase.google.com/docs/remote-config/android#caching_and_throtdling