2016-09-07 17:35:04 +00:00
|
|
|
#import "RCTStatus.h"
|
2017-10-17 10:56:14 +00:00
|
|
|
#import "ReactNativeConfig.h"
|
2017-04-24 14:50:16 +00:00
|
|
|
#import "React/RCTBridge.h"
|
|
|
|
#import "React/RCTEventDispatcher.h"
|
2016-09-07 17:35:04 +00:00
|
|
|
#import <Statusgo/Statusgo.h>
|
2017-05-22 08:43:13 +00:00
|
|
|
|
|
|
|
@interface NSDictionary (BVJSONString)
|
|
|
|
-(NSString*) bv_jsonStringWithPrettyPrint:(BOOL) prettyPrint;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSDictionary (BVJSONString)
|
|
|
|
|
|
|
|
-(NSString*) bv_jsonStringWithPrettyPrint:(BOOL) prettyPrint {
|
|
|
|
NSError *error;
|
|
|
|
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self
|
|
|
|
options:(NSJSONWritingOptions) (prettyPrint ? NSJSONWritingPrettyPrinted : 0)
|
|
|
|
error:&error];
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2017-05-22 08:43:13 +00:00
|
|
|
if (! jsonData) {
|
|
|
|
NSLog(@"bv_jsonStringWithPrettyPrint: error: %@", error.localizedDescription);
|
|
|
|
return @"{}";
|
|
|
|
} else {
|
|
|
|
return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface NSArray (BVJSONString)
|
|
|
|
- (NSString *)bv_jsonStringWithPrettyPrint:(BOOL)prettyPrint;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSArray (BVJSONString)
|
|
|
|
-(NSString*) bv_jsonStringWithPrettyPrint:(BOOL) prettyPrint {
|
|
|
|
NSError *error;
|
|
|
|
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self
|
|
|
|
options:(NSJSONWritingOptions) (prettyPrint ? NSJSONWritingPrettyPrinted : 0)
|
|
|
|
error:&error];
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2017-05-22 08:43:13 +00:00
|
|
|
if (! jsonData) {
|
|
|
|
NSLog(@"bv_jsonStringWithPrettyPrint: error: %@", error.localizedDescription);
|
|
|
|
return @"[]";
|
|
|
|
} else {
|
|
|
|
return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@end
|
2016-09-07 17:35:04 +00:00
|
|
|
|
2016-09-16 15:30:19 +00:00
|
|
|
static bool isStatusInitialized;
|
2016-10-11 14:24:52 +00:00
|
|
|
static RCTBridge *bridge;
|
2016-09-12 08:16:07 +00:00
|
|
|
@implementation Status{
|
|
|
|
}
|
|
|
|
|
2016-10-11 14:24:52 +00:00
|
|
|
-(RCTBridge *)bridge
|
|
|
|
{
|
|
|
|
return bridge;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)setBridge:(RCTBridge *)newBridge
|
|
|
|
{
|
|
|
|
bridge = newBridge;
|
|
|
|
}
|
2016-09-07 17:35:04 +00:00
|
|
|
|
|
|
|
RCT_EXPORT_MODULE();
|
|
|
|
|
2016-09-12 08:16:07 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark - startNode
|
|
|
|
//////////////////////////////////////////////////////////////////// startNode
|
2018-09-07 09:53:43 +00:00
|
|
|
RCT_EXPORT_METHOD(startNode:(NSString *)configString) {
|
2016-09-12 08:16:07 +00:00
|
|
|
#if DEBUG
|
2016-09-23 14:14:43 +00:00
|
|
|
NSLog(@"StartNode() method called");
|
2016-09-12 08:16:07 +00:00
|
|
|
#endif
|
2017-08-21 14:49:31 +00:00
|
|
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
|
|
NSError *error = nil;
|
|
|
|
NSURL *rootUrl =[[fileManager
|
|
|
|
URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask]
|
|
|
|
lastObject];
|
2018-09-07 09:53:43 +00:00
|
|
|
NSURL *absTestnetFolderName = [rootUrl URLByAppendingPathComponent:@"ethereum/testnet"];
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2018-09-07 09:53:43 +00:00
|
|
|
if (![fileManager fileExistsAtPath:absTestnetFolderName.path])
|
|
|
|
[fileManager createDirectoryAtPath:absTestnetFolderName.path withIntermediateDirectories:YES attributes:nil error:&error];
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2017-08-21 14:49:31 +00:00
|
|
|
NSURL *flagFolderUrl = [rootUrl URLByAppendingPathComponent:@"ropsten_flag"];
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2017-08-21 14:49:31 +00:00
|
|
|
if(![fileManager fileExistsAtPath:flagFolderUrl.path]){
|
|
|
|
NSLog(@"remove lightchaindata");
|
2018-09-07 09:53:43 +00:00
|
|
|
NSURL *absLightChainDataUrl = [absTestnetFolderName URLByAppendingPathComponent:@"StatusIM/lightchaindata"];
|
|
|
|
if([fileManager fileExistsAtPath:absLightChainDataUrl.path]) {
|
|
|
|
[fileManager removeItemAtPath:absLightChainDataUrl.path
|
2017-08-21 14:49:31 +00:00
|
|
|
error:nil];
|
2017-04-04 07:15:57 +00:00
|
|
|
}
|
2017-08-21 14:49:31 +00:00
|
|
|
[fileManager createDirectoryAtPath:flagFolderUrl.path
|
|
|
|
withIntermediateDirectories:NO
|
|
|
|
attributes:nil
|
|
|
|
error:&error];
|
|
|
|
}
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2017-08-21 14:49:31 +00:00
|
|
|
NSLog(@"after remove lightchaindata");
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2018-09-07 09:53:43 +00:00
|
|
|
NSURL *absTestnetKeystoreUrl = [absTestnetFolderName URLByAppendingPathComponent:@"keystore"];
|
|
|
|
NSURL *absKeystoreUrl = [rootUrl URLByAppendingPathComponent:@"keystore"];
|
|
|
|
if([fileManager fileExistsAtPath:absTestnetKeystoreUrl.path]){
|
2017-08-21 14:49:31 +00:00
|
|
|
NSLog(@"copy keystore");
|
2018-09-07 09:53:43 +00:00
|
|
|
[fileManager copyItemAtPath:absTestnetKeystoreUrl.path toPath:absKeystoreUrl.path error:nil];
|
|
|
|
[fileManager removeItemAtPath:absTestnetKeystoreUrl.path error:nil];
|
2017-08-21 14:49:31 +00:00
|
|
|
}
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2017-08-21 14:49:31 +00:00
|
|
|
NSLog(@"after lightChainData");
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2017-08-21 14:49:31 +00:00
|
|
|
NSLog(@"preconfig: %@", configString);
|
|
|
|
NSData *configData = [configString dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
NSDictionary *configJSON = [NSJSONSerialization JSONObjectWithData:configData options:NSJSONReadingMutableContainers error:nil];
|
2018-09-07 09:53:43 +00:00
|
|
|
NSString *relativeDataDir = [configJSON objectForKey:@"DataDir"];
|
|
|
|
NSString *absDataDir = [rootUrl.path stringByAppendingString:relativeDataDir];
|
|
|
|
NSURL *absDataDirUrl = [NSURL fileURLWithPath:absDataDir];
|
|
|
|
NSURL *absLogUrl = [absDataDirUrl URLByAppendingPathComponent:@"geth.log"];
|
|
|
|
[configJSON setValue:absDataDirUrl.path forKey:@"DataDir"];
|
|
|
|
[configJSON setValue:absKeystoreUrl.path forKey:@"KeyStoreDir"];
|
|
|
|
[configJSON setValue:absLogUrl.path forKey:@"LogFile"];
|
|
|
|
|
|
|
|
NSString *resultingConfig = [configJSON bv_jsonStringWithPrettyPrint:NO];
|
2017-08-21 14:49:31 +00:00
|
|
|
NSLog(@"node config %@", resultingConfig);
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2018-09-07 09:53:43 +00:00
|
|
|
if(![fileManager fileExistsAtPath:absDataDirUrl.path]) {
|
|
|
|
[fileManager createDirectoryAtPath:absDataDirUrl.path withIntermediateDirectories:YES attributes:nil error:nil];
|
2017-08-21 14:49:31 +00:00
|
|
|
}
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2018-09-07 09:53:43 +00:00
|
|
|
NSLog(@"logUrlPath %@", absLogUrl.path);
|
|
|
|
if(![fileManager fileExistsAtPath:absLogUrl.path]) {
|
2017-05-22 08:43:13 +00:00
|
|
|
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
|
|
|
|
[dict setObject:[NSNumber numberWithInt:511] forKey:NSFilePosixPermissions];
|
2018-09-07 09:53:43 +00:00
|
|
|
[fileManager createFileAtPath:absLogUrl.path contents:nil attributes:dict];
|
2017-08-21 14:49:31 +00:00
|
|
|
}
|
2018-03-29 09:50:55 +00:00
|
|
|
|
2017-08-21 14:49:31 +00:00
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
|
|
|
|
^(void)
|
|
|
|
{
|
|
|
|
char *res = StartNode((char *) [resultingConfig UTF8String]);
|
2018-09-07 09:53:43 +00:00
|
|
|
NSLog(@"StartNode result %@", [NSString stringWithUTF8String: res]);
|
|
|
|
});
|
2016-09-12 08:16:07 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 17:29:59 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark - shouldMoveToInternalStorage
|
|
|
|
//////////////////////////////////////////////////////////////////// shouldMoveToInternalStorage
|
|
|
|
RCT_EXPORT_METHOD(shouldMoveToInternalStorage:(RCTResponseSenderBlock)onResultCallback) {
|
|
|
|
// Android only
|
|
|
|
onResultCallback(@[[NSNull null]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark - moveToInternalStorage
|
|
|
|
//////////////////////////////////////////////////////////////////// moveToInternalStorage
|
|
|
|
RCT_EXPORT_METHOD(moveToInternalStorage:(RCTResponseSenderBlock)onResultCallback) {
|
|
|
|
// Android only
|
|
|
|
onResultCallback(@[[NSNull null]]);
|
|
|
|
}
|
|
|
|
|
2017-08-21 14:49:31 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark - StopNode method
|
|
|
|
//////////////////////////////////////////////////////////////////// StopNode
|
|
|
|
RCT_EXPORT_METHOD(stopNode) {
|
2016-09-12 08:16:07 +00:00
|
|
|
#if DEBUG
|
2017-08-21 14:49:31 +00:00
|
|
|
NSLog(@"StopNode() method called");
|
2016-09-12 08:16:07 +00:00
|
|
|
#endif
|
2017-08-21 14:49:31 +00:00
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
|
|
|
|
^(void)
|
|
|
|
{
|
|
|
|
char *res = StopNode();
|
|
|
|
NSLog(@"StopNode result %@", [NSString stringWithUTF8String: res]);
|
|
|
|
});
|
2016-09-12 08:16:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark - Accounts method
|
|
|
|
//////////////////////////////////////////////////////////////////// createAccount
|
|
|
|
RCT_EXPORT_METHOD(createAccount:(NSString *)password
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
2016-09-23 14:14:43 +00:00
|
|
|
NSLog(@"CreateAccount() method called");
|
2016-09-12 08:16:07 +00:00
|
|
|
#endif
|
|
|
|
char * result = CreateAccount((char *) [password UTF8String]);
|
|
|
|
callback(@[[NSString stringWithUTF8String: result]]);
|
|
|
|
}
|
|
|
|
|
2017-09-16 07:08:47 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
2018-01-04 10:50:14 +00:00
|
|
|
#pragma mark - NotifyUsers method
|
|
|
|
//////////////////////////////////////////////////////////////////// notifyUsers
|
|
|
|
RCT_EXPORT_METHOD(notifyUsers:(NSString *)message
|
|
|
|
payloadJSON:(NSString *)payloadJSON
|
|
|
|
tokensJSON:(NSString *)tokensJSON
|
2017-10-09 09:34:29 +00:00
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
2018-01-04 10:50:14 +00:00
|
|
|
char * result = NotifyUsers((char *) [message UTF8String], (char *) [payloadJSON UTF8String], (char *) [tokensJSON UTF8String]);
|
2017-10-09 09:34:29 +00:00
|
|
|
callback(@[[NSString stringWithUTF8String: result]]);
|
2017-09-16 07:08:47 +00:00
|
|
|
#if DEBUG
|
2018-01-04 10:50:14 +00:00
|
|
|
NSLog(@"NotifyUsers() method called");
|
2017-09-16 07:08:47 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-12-05 10:18:30 +00:00
|
|
|
//////////////////////////////////////////////////////////////////// addPeer
|
|
|
|
RCT_EXPORT_METHOD(addPeer:(NSString *)enode
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
char * result = AddPeer((char *) [enode UTF8String]);
|
|
|
|
callback(@[[NSString stringWithUTF8String: result]]);
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"AddPeer() method called");
|
|
|
|
#endif
|
|
|
|
}
|
2017-09-16 07:08:47 +00:00
|
|
|
|
2016-09-12 08:16:07 +00:00
|
|
|
//////////////////////////////////////////////////////////////////// recoverAccount
|
|
|
|
RCT_EXPORT_METHOD(recoverAccount:(NSString *)passphrase
|
|
|
|
password:(NSString *)password
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
2016-09-23 14:14:43 +00:00
|
|
|
NSLog(@"RecoverAccount() method called");
|
2016-09-12 08:16:07 +00:00
|
|
|
#endif
|
|
|
|
char * result = RecoverAccount((char *) [password UTF8String], (char *) [passphrase UTF8String]);
|
|
|
|
callback(@[[NSString stringWithUTF8String: result]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////// login
|
|
|
|
RCT_EXPORT_METHOD(login:(NSString *)address
|
|
|
|
password:(NSString *)password
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
2016-09-23 14:14:43 +00:00
|
|
|
NSLog(@"Login() method called");
|
2016-09-12 08:16:07 +00:00
|
|
|
#endif
|
|
|
|
char * result = Login((char *) [address UTF8String], (char *) [password UTF8String]);
|
|
|
|
callback(@[[NSString stringWithUTF8String: result]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
2018-08-10 17:15:16 +00:00
|
|
|
#pragma mark - SendTransaction
|
|
|
|
//////////////////////////////////////////////////////////////////// sendTransaction
|
|
|
|
RCT_EXPORT_METHOD(sendTransaction:(NSString *)txArgsJSON
|
2016-09-12 08:16:07 +00:00
|
|
|
password:(NSString *)password
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
2018-08-10 17:15:16 +00:00
|
|
|
NSLog(@"SendTransaction() method called");
|
2016-09-12 08:16:07 +00:00
|
|
|
#endif
|
2018-08-10 17:15:16 +00:00
|
|
|
char * result = SendTransaction((char *) [txArgsJSON UTF8String], (char *) [password UTF8String]);
|
2018-06-03 10:25:14 +00:00
|
|
|
callback(@[[NSString stringWithUTF8String: result]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
2018-08-10 17:15:16 +00:00
|
|
|
#pragma mark - SignMessage
|
|
|
|
//////////////////////////////////////////////////////////////////// signMessage
|
|
|
|
RCT_EXPORT_METHOD(signMessage:(NSString *)message
|
2018-06-03 10:25:14 +00:00
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
2018-08-10 17:15:16 +00:00
|
|
|
NSLog(@"SignMessage() method called");
|
2018-06-03 10:25:14 +00:00
|
|
|
#endif
|
2018-08-10 17:15:16 +00:00
|
|
|
char * result = SignMessage((char *) [message UTF8String]);
|
2016-09-12 08:16:07 +00:00
|
|
|
callback(@[[NSString stringWithUTF8String: result]]);
|
2016-09-07 17:35:04 +00:00
|
|
|
}
|
|
|
|
|
2018-07-19 15:51:06 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark - SignGroupMembership
|
|
|
|
//////////////////////////////////////////////////////////////////// signGroupMembership
|
|
|
|
RCT_EXPORT_METHOD(signGroupMembership:(NSString *)content
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"SignGroupMembership() method called");
|
|
|
|
#endif
|
|
|
|
char * result = SignGroupMembership((char *) [content UTF8String]);
|
|
|
|
callback(@[[NSString stringWithUTF8String: result]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
2018-10-01 08:47:20 +00:00
|
|
|
#pragma mark - ExtractGroupMembershipSignatures
|
|
|
|
//////////////////////////////////////////////////////////////////// extractGroupMembershipSignatures
|
|
|
|
RCT_EXPORT_METHOD(extractGroupMembershipSignatures:(NSString *)content
|
2018-07-19 15:51:06 +00:00
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
2018-10-01 08:47:20 +00:00
|
|
|
NSLog(@"ExtractGroupMembershipSignatures() method called");
|
2018-07-19 15:51:06 +00:00
|
|
|
#endif
|
2018-10-01 08:47:20 +00:00
|
|
|
char * result = ExtractGroupMembershipSignatures((char *) [content UTF8String]);
|
2018-07-19 15:51:06 +00:00
|
|
|
callback(@[[NSString stringWithUTF8String: result]]);
|
|
|
|
}
|
|
|
|
|
2018-11-02 13:48:45 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark - EnableInstallation
|
|
|
|
//////////////////////////////////////////////////////////////////// enableInstallation
|
|
|
|
RCT_EXPORT_METHOD(enableInstallation:(NSString *)content
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"EnableInstallation() method called");
|
|
|
|
#endif
|
|
|
|
char * result = EnableInstallation((char *) [content UTF8String]);
|
|
|
|
callback(@[[NSString stringWithUTF8String: result]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark - DisableInstallation
|
|
|
|
//////////////////////////////////////////////////////////////////// disableInstallation
|
|
|
|
RCT_EXPORT_METHOD(disableInstallation:(NSString *)content
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"DisableInstallation() method called");
|
|
|
|
#endif
|
|
|
|
char * result = DisableInstallation((char *) [content UTF8String]);
|
|
|
|
callback(@[[NSString stringWithUTF8String: result]]);
|
|
|
|
}
|
|
|
|
|
2016-09-12 08:16:07 +00:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark - only android methods
|
|
|
|
////////////////////////////////////////////////////////////////////
|
2016-09-07 17:35:04 +00:00
|
|
|
RCT_EXPORT_METHOD(setAdjustResize) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"setAdjustResize() works only on Android");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(setAdjustPan) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"setAdjustPan() works only on Android");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(setSoftInputMode: (NSInteger) i) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"setSoftInputMode() works only on Android");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-01-16 21:16:55 +00:00
|
|
|
RCT_EXPORT_METHOD(clearCookies) {
|
|
|
|
NSHTTPCookie *cookie;
|
|
|
|
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
|
|
|
|
for (cookie in [storage cookies]) {
|
|
|
|
[storage deleteCookie:cookie];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(clearStorageAPIs) {
|
|
|
|
[[NSURLCache sharedURLCache] removeAllCachedResponses];
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2017-01-16 21:16:55 +00:00
|
|
|
NSString *path = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
|
|
|
|
NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil];
|
|
|
|
for (NSString *string in array) {
|
|
|
|
NSLog(@"Removing %@", [path stringByAppendingPathComponent:string]);
|
2017-10-09 09:34:29 +00:00
|
|
|
if ([[string pathExtension] isEqualToString:@"localstorage"])
|
|
|
|
[[NSFileManager defaultManager] removeItemAtPath:[path stringByAppendingPathComponent:string] error:nil];
|
2017-01-16 21:16:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-10 17:15:16 +00:00
|
|
|
RCT_EXPORT_METHOD(callRPC:(NSString *)payload
|
2017-04-18 14:22:05 +00:00
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
2017-08-01 18:42:16 +00:00
|
|
|
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
2018-06-06 13:19:15 +00:00
|
|
|
char * result = CallRPC((char *) [payload UTF8String]);
|
2017-08-01 18:42:16 +00:00
|
|
|
dispatch_async( dispatch_get_main_queue(), ^{
|
|
|
|
callback(@[[NSString stringWithUTF8String: result]]);
|
|
|
|
});
|
|
|
|
});
|
2017-04-18 14:22:05 +00:00
|
|
|
}
|
|
|
|
|
2018-08-10 17:15:16 +00:00
|
|
|
RCT_EXPORT_METHOD(callPrivateRPC:(NSString *)payload
|
2018-04-18 08:49:15 +00:00
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
|
char * result = CallPrivateRPC((char *) [payload UTF8String]);
|
|
|
|
dispatch_async( dispatch_get_main_queue(), ^{
|
|
|
|
callback(@[[NSString stringWithUTF8String: result]]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-10-05 11:23:25 +00:00
|
|
|
RCT_EXPORT_METHOD(closeApplication) {
|
|
|
|
exit(0);
|
|
|
|
}
|
2017-04-18 14:22:05 +00:00
|
|
|
|
2018-02-26 02:27:29 +00:00
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(connectionChange:(NSString *)type
|
|
|
|
isExpensive:(BOOL)isExpensive) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"ConnectionChange() method called");
|
|
|
|
#endif
|
|
|
|
ConnectionChange((char *) [type UTF8String], isExpensive? 1 : 0);
|
|
|
|
}
|
|
|
|
|
2018-03-16 12:01:10 +00:00
|
|
|
RCT_EXPORT_METHOD(appStateChange:(NSString *)type) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"AppStateChange() method called");
|
|
|
|
#endif
|
|
|
|
AppStateChange((char *) [type UTF8String]);
|
|
|
|
}
|
|
|
|
|
2018-05-01 10:27:04 +00:00
|
|
|
RCT_EXPORT_METHOD(getDeviceUUID:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"getDeviceUUID() method called");
|
|
|
|
#endif
|
|
|
|
NSString* Identifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2018-05-01 10:27:04 +00:00
|
|
|
callback(@[Identifier]);
|
|
|
|
}
|
|
|
|
|
2016-12-14 11:58:17 +00:00
|
|
|
+ (void)signalEvent:(const char *) signal
|
2016-10-11 14:24:52 +00:00
|
|
|
{
|
2016-11-09 10:40:17 +00:00
|
|
|
if(!signal){
|
2016-12-14 11:58:17 +00:00
|
|
|
#if DEBUG
|
2017-10-09 09:34:29 +00:00
|
|
|
NSLog(@"SignalEvent nil");
|
2016-12-14 11:58:17 +00:00
|
|
|
#endif
|
2016-11-09 10:40:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2016-10-11 14:24:52 +00:00
|
|
|
NSString *sig = [NSString stringWithUTF8String:signal];
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"SignalEvent");
|
|
|
|
NSLog(sig);
|
|
|
|
#endif
|
|
|
|
[bridge.eventDispatcher sendAppEventWithName:@"gethEvent"
|
|
|
|
body:@{@"jsonEvent": sig}];
|
2018-05-23 08:41:59 +00:00
|
|
|
|
2016-12-14 11:58:17 +00:00
|
|
|
return;
|
2016-10-11 14:24:52 +00:00
|
|
|
}
|
|
|
|
|
2018-08-03 16:43:37 +00:00
|
|
|
- (bool) is24Hour
|
|
|
|
{
|
|
|
|
NSString *format = [NSDateFormatter dateFormatFromTemplate:@"j" options:0 locale:[NSLocale currentLocale]];
|
|
|
|
return ([format rangeOfString:@"a"].location == NSNotFound);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *)constantsToExport
|
|
|
|
{
|
|
|
|
return @{
|
|
|
|
@"is24Hour": @(self.is24Hour),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-08-23 01:54:29 +00:00
|
|
|
+ (BOOL)requiresMainQueueSetup
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2016-09-07 17:35:04 +00:00
|
|
|
@end
|