Switching Firebase configuration file at runtime

时间:2017-08-03 07:11:27

标签: ios objective-c firebase configuration-files firebase-analytics

My iOS app uses two Firebase configuration files, one for development and one for production. How can I switch between the two during runtime? When I attempt the switch with [FIRApp configureWithOptions:options];, I get the error:

 Default app has already been configured.

So I have tried to clear the current config [FIRApp deleteApp] before switching to the other config, however the deleteApp method is a private method and is not accessible.

2 个答案:

答案 0 :(得分:1)

初始化firebase时尝试此操作:

    NSString *filePath;

#ifdef DEBUG
    filePath = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info-Debug" ofType:@"plist"];
#else
    filePath = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info-Live" ofType:@"plist"];
#endif

    FIROptions *options = [[FIROptions alloc] initWithContentsOfFile:filePath];
    [FIRApp configureWithOptions:options];

答案 1 :(得分:1)

我错误地调用了deleteApp方法。它应该在defaultApp上调用,例如:

 [[FIRApp defaultApp] deleteApp:^(BOOL success) { ... }];