diff options
author | Ryan Wilson <wilsonryan@google.com> | 2017-08-17 11:15:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-17 11:15:25 -0400 |
commit | 566665e3bbb47ed7e77f35f29c62bbc5c737a769 (patch) | |
tree | cc2501b7f63c73d3dfd040375d9925dfb5f3ce71 /Firebase/Database | |
parent | 55476604aabbb35be7ed7d871236644c1e1d395a (diff) |
Delete app from Database when deleted in Core. (#194)
* Delete an app from Database when deleted in Core.
When a FIRApp is deleted in Core, it should also be deleted from
the instances array in Database.
See #160 for more details.
* Add tests for deleting databases.
* Add call to clean up deleted FIRDatabase instance.
Diffstat (limited to 'Firebase/Database')
-rw-r--r-- | Firebase/Database/Api/FIRDatabase.m | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Firebase/Database/Api/FIRDatabase.m b/Firebase/Database/Api/FIRDatabase.m index 38ccd54..6ee163f 100644 --- a/Firebase/Database/Api/FIRDatabase.m +++ b/Firebase/Database/Api/FIRDatabase.m @@ -42,6 +42,26 @@ #define STR_EXPAND(x) #x static const char *FIREBASE_SEMVER = (const char *)STR(FIRDatabase_VERSION); ++ (void)load { + NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; + [center addObserverForName:kFIRAppDeleteNotification + object:nil + queue:nil + usingBlock:^(NSNotification * _Nonnull note) { + NSString *appName = note.userInfo[kFIRAppNameKey]; + if (appName == nil) { return; } + + NSMutableDictionary *instances = [self instances]; + @synchronized (instances) { + FIRDatabase *deletedApp = instances[appName]; + // Clean up the deleted instance in an effort to remove any resources still in use. + // Note: Any leftover instances of this exact database will be invalid. + [FRepoManager disposeRepos:deletedApp.config]; + [instances removeObjectForKey:appName]; + } + }]; +} + /** * A static NSMutableDictionary of FirebaseApp names to FirebaseDatabase instance. To ensure thread- * safety, it should only be accessed in databaseForApp, which is synchronized. |