diff --git a/__mocks__/react-native-mmkv-storage.js b/__mocks__/react-native-mmkv-storage.js index e34fed189..689a2d4c8 100644 --- a/__mocks__/react-native-mmkv-storage.js +++ b/__mocks__/react-native-mmkv-storage.js @@ -4,8 +4,10 @@ export class MMKVLoader { } setProcessingMode = jest.fn().mockImplementation(() => ({ - withEncryption: jest.fn().mockImplementation(() => ({ - initialize: jest.fn().mockImplementation(() => {}) + setAccessibleIOS: jest.fn().mockImplementation(() => ({ + withEncryption: jest.fn().mockImplementation(() => ({ + initialize: jest.fn().mockImplementation(() => {}) + })) })) })); } @@ -14,4 +16,8 @@ export const ProcessingModes = { MULTI_PROCESS: '' }; +export const IOSAccessibleStates = { + AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY: '' +}; + export const create = jest.fn(); diff --git a/app/lib/methods/userPreferences.ts b/app/lib/methods/userPreferences.ts index b46e0f2f9..f9b82dec4 100644 --- a/app/lib/methods/userPreferences.ts +++ b/app/lib/methods/userPreferences.ts @@ -1,8 +1,9 @@ -import { create, MMKVLoader, MMKVInstance, ProcessingModes } from 'react-native-mmkv-storage'; +import { create, MMKVLoader, MMKVInstance, ProcessingModes, IOSAccessibleStates } from 'react-native-mmkv-storage'; const MMKV = new MMKVLoader() // MODES.MULTI_PROCESS = ACCESSIBLE BY APP GROUP (iOS) .setProcessingMode(ProcessingModes.MULTI_PROCESS) + .setAccessibleIOS(IOSAccessibleStates.AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY) .withEncryption() .initialize(); diff --git a/patches/react-native-mmkv-storage+0.9.1.patch b/patches/react-native-mmkv-storage+0.9.1.patch index c757b6c7a..abc742e72 100644 --- a/patches/react-native-mmkv-storage+0.9.1.patch +++ b/patches/react-native-mmkv-storage+0.9.1.patch @@ -1,3 +1,51 @@ +diff --git a/node_modules/react-native-mmkv-storage/ios/MMKVNative.mm b/node_modules/react-native-mmkv-storage/ios/MMKVNative.mm +index 9af089d..12ff53b 100644 +--- a/node_modules/react-native-mmkv-storage/ios/MMKVNative.mm ++++ b/node_modules/react-native-mmkv-storage/ios/MMKVNative.mm +@@ -37,12 +37,43 @@ - (instancetype)init + rPath = rootDir; + _secureStorage = [[SecureStorage alloc] init]; + [MMKV initializeMMKV:rootDir]; ++ [self addSkipBackupAttributeToDir:rootDir]; + }); + + + return self; + } + ++- (BOOL)addSkipBackupAttributeToURLAtPath:(NSURL *)url ++{ ++ if (!url) return NO; ++ if (![[NSFileManager defaultManager] fileExistsAtPath:url.path]) return NO; ++ ++ NSError *error = nil; ++ NSNumber *value = nil; ++ BOOL success = [url getResourceValue:&value forKey:NSURLIsExcludedFromBackupKey error:&error]; ++ if (value.boolValue == YES) { ++ NSLog(@"%@ already marked for backup exclusion", [url lastPathComponent]); ++ return YES; ++ } ++ ++ success = [url setResourceValue:[NSNumber numberWithBool:YES] ++ forKey:NSURLIsExcludedFromBackupKey error:&error]; ++ if(!success){ ++ NSLog(@"Error excluding %@ from backup: %@", [url lastPathComponent], error); ++ } else { ++ NSLog(@"Succesfully marked %@ for backup exclusion", [url lastPathComponent]); ++ } ++ return success; ++} ++ ++- (BOOL) addSkipBackupAttributeToDir:(NSString *)path ++{ ++ if (!path) return NO; ++ NSURL *pathUrl = [[NSURL alloc] initFileURLWithPath:path isDirectory:YES]; ++ return [self addSkipBackupAttributeToURLAtPath:pathUrl]; ++} ++ + MMKV *getInstance(NSString *ID) { + if ([[mmkvInstances allKeys] containsObject:ID]) { + MMKV *kv = [mmkvInstances objectForKey:ID]; diff --git a/node_modules/react-native-mmkv-storage/ios/SecureStorage.m b/node_modules/react-native-mmkv-storage/ios/SecureStorage.m index dbea26b..2483375 100644 --- a/node_modules/react-native-mmkv-storage/ios/SecureStorage.m