diff --git a/native/ios/Comm/AppDelegate.mm b/native/ios/Comm/AppDelegate.mm --- a/native/ios/Comm/AppDelegate.mm +++ b/native/ios/Comm/AppDelegate.mm @@ -7,7 +7,6 @@ #import #import -#import #import #import #import @@ -15,8 +14,6 @@ #import #import -#import - #import "CommCoreModule.h" #import "CommSecureStore.h" #import "CommSecureStoreIOSWrapper.h" @@ -62,12 +59,14 @@ } @end -@interface CommSecureStoreIOSWrapper () -- (void)init:(EXSecureStore *)secureStore; -@end - @implementation AppDelegate +- (BOOL)application:(UIApplication *)application + willFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + [self attemptDatabaseInitialization]; + return YES; +} + - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { #ifdef FB_SONARKIT_ENABLED @@ -103,17 +102,6 @@ rootView.loadingViewFadeDelay = 0; rootView.loadingViewFadeDuration = 0.001; - EXModuleRegistryProvider *moduleRegistryProvider = - [[EXModuleRegistryProvider alloc] init]; - EXSecureStore *secureStore = - (EXSecureStore *)[[moduleRegistryProvider moduleRegistry] - getExportedModuleOfClass:EXSecureStore.class]; - [[CommSecureStoreIOSWrapper sharedInstance] init:secureStore]; - - // initialize SQLiteQueryExecutor - std::string sqliteFilePath = - std::string([[Tools getSQLiteFilePath] UTF8String]); - comm::SQLiteQueryExecutor::initialize(sqliteFilePath); return YES; } @@ -243,6 +231,13 @@ makeRuntimeConfig(3072)); } +- (void)attemptDatabaseInitialization { + [[CommSecureStoreIOSWrapper sharedInstance] initialize]; + std::string sqliteFilePath = + std::string([[Tools getSQLiteFilePath] UTF8String]); + comm::SQLiteQueryExecutor::initialize(sqliteFilePath); +} + // Copied from // ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/OnLoad.cpp static ::hermes::vm::RuntimeConfig diff --git a/native/ios/Comm/CommSecureStoreIOSWrapper.h b/native/ios/Comm/CommSecureStoreIOSWrapper.h --- a/native/ios/Comm/CommSecureStoreIOSWrapper.h +++ b/native/ios/Comm/CommSecureStoreIOSWrapper.h @@ -1,12 +1,13 @@ #pragma once - #import +#import #import @interface CommSecureStoreIOSWrapper : NSObject + (id)sharedInstance; +- (void)initialize; - (void)set:(NSString *)key value:(NSString *)value; - (NSString *)get:(NSString *)key; @end diff --git a/native/ios/Comm/CommSecureStoreIOSWrapper.mm b/native/ios/Comm/CommSecureStoreIOSWrapper.mm --- a/native/ios/Comm/CommSecureStoreIOSWrapper.mm +++ b/native/ios/Comm/CommSecureStoreIOSWrapper.mm @@ -3,7 +3,7 @@ #import "CommSecureStoreIOSWrapper.h" @interface CommSecureStoreIOSWrapper () -@property(nonatomic, assign) EXSecureStore *secureStore; +@property(nonatomic, strong) EXSecureStore *secureStore; @property(nonatomic, strong) NSDictionary *options; @end @@ -30,8 +30,17 @@ return shared; } -- (void)init:(EXSecureStore *)secureStore { - _secureStore = secureStore; +- (void)initialize { + if ([self secureStore] != nil) { + return; + } + + EXModuleRegistryProvider *moduleRegistryProvider = + [[EXModuleRegistryProvider alloc] init]; + EXSecureStore *secureStore = + (EXSecureStore *)[[moduleRegistryProvider moduleRegistry] + getExportedModuleOfClass:EXSecureStore.class]; + self.secureStore = secureStore; } - (void)set:(NSString *)key value:(NSString *)value {