Skip to content

Commit 500e182

Browse files
authored
Fix Remote Config pre-configure access. (#9551)
* Fix Remote Config pre-configure access. Currently, when `RemoteConfig.remoteConfig()` is called before `FirebaseApp.configure()` is called, Similar to Database, AppCheck, and others we'll now throw an ObjC exception. We're not going to make it nullable or throw a Swift compatible error since it'd affect the callsite of every usage (either a `?` or `try`) and this is deemed a programming error: `configure()` has to be called first. Fixes #8640 * CHANGELOG
1 parent fd1c0f6 commit 500e182

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

FirebaseRemoteConfig/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# v9.0.0
2+
- [changed] The `remoteConfig()` singleton now throws an exception when called before
3+
`FirebaseApp.configure()`. (#8640)
4+
15
# v8.10.0
26
- [fixed] Fixed cached config not loading if device is locked. (#8807)
37

FirebaseRemoteConfig/Sources/FIRRemoteConfig.m

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ + (nonnull FIRRemoteConfig *)remoteConfigWithApp:(FIRApp *_Nonnull)firebaseApp {
7878

7979
+ (nonnull FIRRemoteConfig *)remoteConfigWithFIRNamespace:(NSString *_Nonnull)firebaseNamespace {
8080
if (![FIRApp isDefaultAppConfigured]) {
81-
FIRLogError(kFIRLoggerRemoteConfig, @"I-RCN000047",
82-
@"FIRApp not configured. Please make sure you have called [FIRApp configure]");
83-
// TODO: Maybe throw an exception here? That'd be a breaking change though, but at this point
84-
// RC can't work as expected.
81+
[NSException raise:@"FIRAppNotConfigured"
82+
format:@"The default `FirebaseApp` instance must be configured before the "
83+
@"default Remote Config instance can be initialized. One way to ensure this "
84+
@"is to call `FirebaseApp.configure()` in the App Delegate's "
85+
@"`application(_:didFinishLaunchingWithOptions:)` or the `@main` struct's "
86+
@"initializer in SwiftUI."];
8587
}
8688

8789
return [FIRRemoteConfig remoteConfigWithFIRNamespace:firebaseNamespace app:[FIRApp defaultApp]];
@@ -99,10 +101,12 @@ + (nonnull FIRRemoteConfig *)remoteConfigWithFIRNamespace:(NSString *_Nonnull)fi
99101
+ (FIRRemoteConfig *)remoteConfig {
100102
// If the default app is not configured at this point, warn the developer.
101103
if (![FIRApp isDefaultAppConfigured]) {
102-
FIRLogError(kFIRLoggerRemoteConfig, @"I-RCN000047",
103-
@"FIRApp not configured. Please make sure you have called [FIRApp configure]");
104-
// TODO: Maybe throw an exception here? That'd be a breaking change though, but at this point
105-
// RC can't work as expected.
104+
[NSException raise:@"FIRAppNotConfigured"
105+
format:@"The default `FirebaseApp` instance must be configured before the "
106+
@"default Remote Config instance can be initialized. One way to ensure this "
107+
@"is to call `FirebaseApp.configure()` in the App Delegate's "
108+
@"`application(_:didFinishLaunchingWithOptions:)` or the `@main` struct's "
109+
@"initializer in SwiftUI."];
106110
}
107111

108112
return [FIRRemoteConfig remoteConfigWithFIRNamespace:FIRNamespaceGoogleMobilePlatform

0 commit comments

Comments
 (0)