aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firebase/Core/FIRApp.m
diff options
context:
space:
mode:
Diffstat (limited to 'Firebase/Core/FIRApp.m')
-rw-r--r--Firebase/Core/FIRApp.m33
1 files changed, 33 insertions, 0 deletions
diff --git a/Firebase/Core/FIRApp.m b/Firebase/Core/FIRApp.m
index 91a7aba..2ea7f6b 100644
--- a/Firebase/Core/FIRApp.m
+++ b/Firebase/Core/FIRApp.m
@@ -19,6 +19,8 @@
#import "Private/FIRAnalyticsConfiguration+Internal.h"
#import "Private/FIRAppInternal.h"
#import "Private/FIRBundleUtil.h"
+#import "Private/FIRComponentContainerInternal.h"
+#import "Private/FIRCoreConfigurable.h"
#import "Private/FIRLogger.h"
#import "Private/FIROptionsInternal.h"
#import "third_party/FIRAppEnvironmentUtil.h"
@@ -76,6 +78,12 @@ NSString *const FIRAuthStateDidChangeInternalNotificationUIDKey =
*/
static NSString *const kPlistURL = @"https://console.firebase.google.com/";
+/**
+ * An array of all classes that registered as `FIRCoreConfigurable` in order to receive lifecycle
+ * events from Core.
+ */
+static NSMutableArray<Class<FIRCoreConfigurable>> *gRegisteredAsConfigurable;
+
@interface FIRApp ()
@property(nonatomic) BOOL alreadySentConfigureNotification;
@@ -233,6 +241,10 @@ static NSMutableDictionary *sLibraryVersions;
@synchronized([self class]) {
if (sAllApps && sAllApps[self.name]) {
FIRLogDebug(kFIRLoggerCore, @"I-COR000006", @"Deleting app named %@", self.name);
+
+ // Remove all cached instances from the container before deleting the app.
+ [self.container removeAllCachedInstances];
+
[sAllApps removeObjectForKey:self.name];
[self clearDataCollectionSwitchFromUserDefaults];
if ([self.name isEqualToString:kFIRDefaultAppName]) {
@@ -280,6 +292,8 @@ static NSMutableDictionary *sLibraryVersions;
_name = [name copy];
_options = [options copy];
_options.editingLocked = YES;
+ _isDefaultApp = [name isEqualToString:kFIRDefaultAppName];
+ _container = [[FIRComponentContainer alloc] initWithApp:self];
FIRApp *app = sAllApps[name];
_alreadySentConfigureNotification = app.alreadySentConfigureNotification;
@@ -384,6 +398,7 @@ static NSMutableDictionary *sLibraryVersions;
#pragma mark - private
+ (void)sendNotificationsToSDKs:(FIRApp *)app {
+ // TODO: Remove this notification once all SDKs are registered with `FIRCoreConfigurable`.
NSNumber *isDefaultApp = [NSNumber numberWithBool:(app == sDefaultApp)];
NSDictionary *appInfoDict = @{
kFIRAppNameKey : app.name,
@@ -393,6 +408,12 @@ static NSMutableDictionary *sLibraryVersions;
[[NSNotificationCenter defaultCenter] postNotificationName:kFIRAppReadyToConfigureSDKNotification
object:self
userInfo:appInfoDict];
+
+ // This is the new way of sending information to SDKs.
+ // TODO: Do we want this on a background thread, maybe?
+ for (Class<FIRCoreConfigurable> library in gRegisteredAsConfigurable) {
+ [library configureWithApp:app];
+ }
}
+ (NSError *)errorForMissingOptions {
@@ -430,6 +451,18 @@ static NSMutableDictionary *sLibraryVersions;
userInfo:errorDict];
}
++ (void)registerAsConfigurable:(Class<FIRCoreConfigurable>)klass {
+ // This is called at +load time, keep the work to a minimum.
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ gRegisteredAsConfigurable = [[NSMutableArray alloc] initWithCapacity:1];
+ });
+
+ NSAssert([(Class)klass conformsToProtocol:@protocol(FIRCoreConfigurable)],
+ @"The class being registered (%@) must conform to `FIRCoreConfigurable`.", klass);
+ [gRegisteredAsConfigurable addObject:klass];
+}
+
+ (BOOL)isDefaultAppConfigured {
return (sDefaultApp != nil);
}