Skip to content

Commit

Permalink
Fix Remote Config pre-configure access.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ryanwilson committed Mar 31, 2022
1 parent fd1c0f6 commit 14efb5f
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions FirebaseRemoteConfig/Sources/FIRRemoteConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ + (nonnull FIRRemoteConfig *)remoteConfigWithApp:(FIRApp *_Nonnull)firebaseApp {

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

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

return [FIRRemoteConfig remoteConfigWithFIRNamespace:FIRNamespaceGoogleMobilePlatform
Expand Down

0 comments on commit 14efb5f

Please sign in to comment.