forked from ospfranco/react-native-quick-sqlite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuickSQLite.mm
42 lines (29 loc) · 1018 Bytes
/
QuickSQLite.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#import "QuickSQLite.h"
#import <React/RCTBridge+Private.h>
#import <React/RCTUtils.h>
#import <ReactCommon/RCTTurboModule.h>
#import <jsi/jsi.h>
#import "../cpp/bindings.h"
@implementation QuickSQLite
RCT_EXPORT_MODULE(QuickSQLite)
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
NSLog(@"Installing QuickSQLite module...");
RCTBridge *bridge = [RCTBridge currentBridge];
RCTCxxBridge *cxxBridge = (RCTCxxBridge *)bridge;
if (cxxBridge == nil) {
return @false;
}
using namespace facebook;
auto jsiRuntime = (jsi::Runtime *)cxxBridge.runtime;
if (jsiRuntime == nil) {
return @false;
}
auto &runtime = *jsiRuntime;
auto callInvoker = bridge.jsCallInvoker;
// Get iOS app's document directory (to safely store database .sqlite3 file)
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true);
NSString *documentPath = [paths objectAtIndex:0];
osp::install(runtime, callInvoker,[documentPath UTF8String]);
return @true;
}
@end