Skip to content

Commit 4aaa1cc

Browse files
committed
seperate SecureStorage init and MMKV
1 parent e0f75e1 commit 4aaa1cc

File tree

4 files changed

+84
-55
lines changed

4 files changed

+84
-55
lines changed

ios/MMKVNative.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
#if __has_include("RCTBridgeModule.h")
3+
#import "RCTBridgeModule.h"
4+
#else
5+
#import <React/RCTBridgeModule.h>
6+
#endif
7+
8+
@interface MMKVNative : NSObject <RCTBridgeModule>
9+
10+
@property (nonatomic, assign) BOOL setBridgeOnMainQueue;
11+
12+
@end
13+
14+

ios/MMKVStorage.mm renamed to ios/MMKVNative.mm

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#import "MMKVStorage.h"
2-
#import "SecureStorage.h"
1+
#import "MMKVNative.h"
32
#import "YeetJSIUtils.h"
43

54
#import <React/RCTBridge+Private.h>
@@ -12,15 +11,12 @@
1211
using namespace jsi;
1312
using namespace std;
1413

15-
16-
17-
@implementation MMKVStorage
14+
@implementation MMKVNative
1815
@synthesize bridge = _bridge;
1916
@synthesize methodQueue = _methodQueue;
2017
NSString *rPath = @"";
2118
NSMutableDictionary *mmkvInstances;
2219

23-
SecureStorage *secureStorage;
2420

2521
RCT_EXPORT_MODULE()
2622

@@ -144,51 +140,6 @@ void removeKeyFromIndexer(MMKV *kv, NSString* key) {
144140
}
145141

146142

147-
148-
149-
150-
151-
152-
153-
#pragma mark setSecureKey
154-
RCT_EXPORT_METHOD(setSecureKey: (NSString *)alias value:(NSString *)value
155-
options: (NSDictionary *)options
156-
callback:(RCTResponseSenderBlock)callback
157-
)
158-
{
159-
160-
[secureStorage setSecureKey:alias value:value options:options callback:callback];
161-
162-
}
163-
164-
#pragma mark getSecureKey
165-
RCT_EXPORT_METHOD(getSecureKey:(NSString *)alias
166-
callback:(RCTResponseSenderBlock)callback)
167-
{
168-
169-
[secureStorage getSecureKey:alias callback:callback];
170-
171-
172-
}
173-
174-
#pragma mark secureKeyExists
175-
RCT_EXPORT_METHOD(secureKeyExists:(NSString *)key
176-
callback:(RCTResponseSenderBlock)callback)
177-
{
178-
179-
[secureStorage secureKeyExists:key callback:callback];
180-
181-
}
182-
#pragma mark removeSecureKey
183-
RCT_EXPORT_METHOD(removeSecureKey:(NSString *)key
184-
callback:(RCTResponseSenderBlock)callback)
185-
{
186-
187-
[secureStorage removeSecureKey:key callback:callback];
188-
189-
}
190-
191-
192143
static void install(jsi::Runtime & jsiRuntime)
193144
{
194145

@@ -736,8 +687,6 @@ - (void)setBridge:(RCTBridge *)bridge
736687
if (!cxxBridge.runtime) {
737688
return;
738689
}
739-
740-
secureStorage = [[SecureStorage alloc]init];
741690
mmkvInstances = [NSMutableDictionary dictionary];
742691

743692
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
@@ -751,3 +700,4 @@ - (void)setBridge:(RCTBridge *)bridge
751700

752701
@end
753702

703+

ios/MMKVStorage.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,5 @@
77

88
@interface MMKVStorage : NSObject <RCTBridgeModule>
99

10-
@property (nonatomic, assign) BOOL setBridgeOnMainQueue;
11-
1210
@end
1311

ios/MMKVStorage.m

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#import "MMKVStorage.h"
2+
#import "SecureStorage.h"
3+
4+
#import <React/RCTUtils.h>
5+
6+
7+
@implementation MMKVStorage
8+
9+
SecureStorage *secureStorage;
10+
11+
RCT_EXPORT_MODULE()
12+
13+
+ (BOOL)requiresMainQueueSetup
14+
{
15+
return YES;
16+
}
17+
18+
- (id)init
19+
{
20+
self = [super init];
21+
if (self) {
22+
secureStorage = [[SecureStorage alloc]init];
23+
}
24+
25+
return self;
26+
}
27+
28+
#pragma mark setSecureKey
29+
RCT_EXPORT_METHOD(setSecureKey: (NSString *)alias value:(NSString *)value
30+
options: (NSDictionary *)options
31+
callback:(RCTResponseSenderBlock)callback
32+
)
33+
{
34+
35+
[secureStorage setSecureKey:alias value:value options:options callback:callback];
36+
37+
}
38+
39+
#pragma mark getSecureKey
40+
RCT_EXPORT_METHOD(getSecureKey:(NSString *)alias
41+
callback:(RCTResponseSenderBlock)callback)
42+
{
43+
44+
[secureStorage getSecureKey:alias callback:callback];
45+
46+
47+
}
48+
49+
#pragma mark secureKeyExists
50+
RCT_EXPORT_METHOD(secureKeyExists:(NSString *)key
51+
callback:(RCTResponseSenderBlock)callback)
52+
{
53+
54+
[secureStorage secureKeyExists:key callback:callback];
55+
56+
}
57+
#pragma mark removeSecureKey
58+
RCT_EXPORT_METHOD(removeSecureKey:(NSString *)key
59+
callback:(RCTResponseSenderBlock)callback)
60+
{
61+
62+
[secureStorage removeSecureKey:key callback:callback];
63+
64+
}
65+
66+
@end
67+

0 commit comments

Comments
 (0)