Skip to content

Commit 3c16566

Browse files
authored
Don't call FIRConfiguration setLoggerLevel: before FIRApp exists. (#843)
* Don't call FIRConfiguration setLoggerLevel: before FIRApp exists. Instead, cache the value, and call setLoggerLevel later, after the iOS FIRApp instance is created. * Add release note for this fix. * Revert "Disable logging during AddCallback, which initializes too early. (#827)" This reverts commit cf20054. This PR should fix the issue in a more general way.
1 parent b7aa15b commit 3c16566

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

app/src/app_ios.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@
1717
#ifndef FIREBASE_APP_SRC_APP_IOS_H_
1818
#define FIREBASE_APP_SRC_APP_IOS_H_
1919
#include "FIRApp.h"
20+
#include "FIRConfiguration.h"
2021
#include "app/src/util_ios.h"
2122

2223
namespace firebase {
2324

2425
namespace internal {
2526
OBJ_C_PTR_WRAPPER_NAMED(AppInternal, FIRApp);
27+
28+
void SetFirConfigurationLoggerLevel(FIRLoggerLevel level);
29+
2630
} // namespace internal
2731

2832
} // namespace firebase

app/src/app_ios.mm

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ static void PlatformOptionsToAppOptions(FIROptions* platform_options, AppOptions
133133
return platform_app;
134134
}
135135

136+
// Settings cached by SetFirConfigurationLoggerLevel if App wasn't already initialized.
137+
static bool g_delayed_fir_configuration_logger_level_set = false;
138+
static FIRLoggerLevel g_delayed_fir_configuration_logger_level = FIRLoggerLevelWarning;
139+
136140
// Create an iOS FIRApp instance.
137141
static FIRApp* CreatePlatformApp(const AppOptions& options, const char* name) {
138142
__block FIRApp* platform_app = nil;
@@ -155,6 +159,14 @@ static void PlatformOptionsToAppOptions(FIROptions* platform_options, AppOptions
155159
[FIRApp configureWithName:@(name) options:platform_options];
156160
}
157161
platform_app = GetPlatformAppByName(name);
162+
// If the logger level was cached due to logging happening prior to
163+
// App's initialization, apply the delayed setting now, when FIRApp
164+
// is guaranteed to exist and we are in the main thread.
165+
if (g_delayed_fir_configuration_logger_level_set) {
166+
g_delayed_fir_configuration_logger_level_set = false;
167+
[[FIRConfiguration sharedInstance]
168+
setLoggerLevel:g_delayed_fir_configuration_logger_level];
169+
}
158170
} @catch (NSException* e) {
159171
LogError("Unable to configure Firebase app (%s)",
160172
util::NSStringToString(e.reason).c_str());
@@ -276,4 +288,22 @@ static void PlatformOptionsToAppOptions(FIROptions* platform_options, AppOptions
276288

277289
FIRApp* App::GetPlatformApp() const { return internal_->get(); }
278290

291+
namespace internal {
292+
293+
void SetFirConfigurationLoggerLevel(FIRLoggerLevel level) {
294+
// Check if a FIRApp has been created. FIRApp.allApps will return a
295+
// list of all FIRApps, or nil if no FIRApp has been created yet.
296+
if (FIRApp.allApps != nil) {
297+
// FIRApp has already been initialized, it's safe to set this
298+
// value now.
299+
[[FIRConfiguration sharedInstance] setLoggerLevel:level];
300+
} else {
301+
// FIRApp has not yet been initialized. Cache this value to set
302+
// later, in CreatePlatformApp().
303+
g_delayed_fir_configuration_logger_level = level;
304+
g_delayed_fir_configuration_logger_level_set = true;
305+
}
306+
}
307+
} // namespace internal
308+
279309
} // namespace firebase

app/src/log_ios.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#import "FIRConfiguration.h"
2222

23+
#include "app/src/app_ios.h"
2324
#include "app/src/include/firebase/internal/common.h"
2425

2526
#include <stdarg.h>
@@ -61,7 +62,7 @@ void LogInitialize() {
6162
// Set the platform specific SDK log level.
6263
void LogSetPlatformLevel(LogLevel level) {
6364
assert(level < FIREBASE_ARRAYSIZE(kCppToIOSLogLevel));
64-
[[FIRConfiguration sharedInstance] setLoggerLevel:kCppToIOSLogLevel[level]];
65+
firebase::internal::SetFirConfigurationLoggerLevel(kCppToIOSLogLevel[level]);
6566
}
6667

6768
// Log a firebase message.

app/src/util.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,13 @@ void AppCallback::AddCallback(AppCallback* callback) {
227227
}
228228
std::string name = callback->module_name();
229229
if (callbacks_->find(name) != callbacks_->end()) {
230+
LogWarning(
231+
"%s is already registered for callbacks on app initialization, "
232+
"ignoring.",
233+
name.c_str());
230234
} else {
235+
LogDebug("Registered app initializer %s (enabled: %d)", name.c_str(),
236+
callback->enabled() ? 1 : 0);
231237
(*callbacks_)[name] = callback;
232238
}
233239
}

release_build_files/readme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,11 @@ workflow use only during the development of your app, not for publicly shipping
567567
code.
568568

569569
## Release Notes
570+
### Upcoming Release
571+
- Changes
572+
- General (iOS): Fixed additional issues on iOS 15 caused by early
573+
initialization of Firebase iOS SDK.
574+
570575
### 8.9.0
571576
- Changes
572577
- General (iOS): Fixed an intermittent crash on iOS 15 caused by

0 commit comments

Comments
 (0)