Skip to content

Commit 15eaafe

Browse files
committed
Add init & extract storage directory path creation
1 parent a30fc51 commit 15eaafe

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

ios/RNCAsyncStorage.m

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,23 @@ static void RCTAppendError(NSDictionary *error, NSMutableArray<NSDictionary *> *
7878
return nil;
7979
}
8080

81+
static NSString *RCTCreateStorageDirectoryPath(NSString *storageDir) {
82+
NSString *storageDirectoryPath;
83+
#if TARGET_OS_TV
84+
storageDirectoryPath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject;
85+
#else
86+
storageDirectoryPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
87+
#endif
88+
storageDirectoryPath = [storageDirectoryPath stringByAppendingPathComponent:RCTStorageDirectory];
89+
return storageDirectoryPath;
90+
}
91+
8192
static NSString *RCTGetStorageDirectory()
8293
{
8394
static NSString *storageDirectory = nil;
8495
static dispatch_once_t onceToken;
8596
dispatch_once(&onceToken, ^{
86-
#if TARGET_OS_TV
87-
storageDirectory = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject;
88-
#else
89-
storageDirectory = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
90-
#endif
91-
storageDirectory = [storageDirectory stringByAppendingPathComponent:RCTStorageDirectory];
97+
storageDirectory = RCTCreateStorageDirectoryPath(RCTStorageDirectory);
9298
});
9399
return storageDirectory;
94100
}
@@ -168,6 +174,12 @@ static dispatch_queue_t RCTGetMethodQueue()
168174
return error ? RCTMakeError(@"Failed to delete storage directory.", error, nil) : nil;
169175
}
170176

177+
static void RCTPerformDirectoryMigrationCheck() {
178+
// NSString *oldRCTStorageDirectory = @"RNCAsyncLocalStorage_V1";
179+
// NSString *storageDir = RCTCreateStorageDirectoryPath(oldRCTStorageDirectory);
180+
// printf("%s%s\n", "TESTING: ", [storageDir UTF8String]);
181+
}
182+
171183
#pragma mark - RNCAsyncStorage
172184

173185
@implementation RNCAsyncStorage
@@ -179,6 +191,19 @@ @implementation RNCAsyncStorage
179191
NSMutableDictionary<NSString *, NSString *> *_manifest;
180192
}
181193

194+
+ (BOOL)requiresMainQueueSetup {
195+
return YES;
196+
}
197+
198+
- (instancetype)init
199+
{
200+
if (!(self = [super init])) {
201+
return nil;
202+
}
203+
RCTPerformDirectoryMigrationCheck();
204+
return self;
205+
}
206+
182207
RCT_EXPORT_MODULE()
183208

184209
- (dispatch_queue_t)methodQueue
@@ -441,7 +466,7 @@ - (BOOL)_passthroughDelegate
441466
}
442467

443468
RCT_EXPORT_METHOD(multiMerge:(NSArray<NSArray<NSString *> *> *)kvPairs
444-
callback:(RCTResponseSenderBlock)callback)
469+
callback:(RCTResponseSenderBlock)callback)
445470
{
446471
if (self.delegate != nil) {
447472
NSMutableArray<NSString *> *keys = [NSMutableArray arrayWithCapacity:kvPairs.count];
@@ -575,3 +600,4 @@ - (BOOL)_passthroughDelegate
575600
}
576601

577602
@end
603+

0 commit comments

Comments
 (0)