fix: disable backup of mmkv keys in icloud (#5165)
* set accessible key to mmkv * update patch package
This commit is contained in:
parent
f78f6f33ff
commit
96bb25e5b4
|
@ -4,9 +4,11 @@ export class MMKVLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
setProcessingMode = jest.fn().mockImplementation(() => ({
|
setProcessingMode = jest.fn().mockImplementation(() => ({
|
||||||
|
setAccessibleIOS: jest.fn().mockImplementation(() => ({
|
||||||
withEncryption: jest.fn().mockImplementation(() => ({
|
withEncryption: jest.fn().mockImplementation(() => ({
|
||||||
initialize: jest.fn().mockImplementation(() => {})
|
initialize: jest.fn().mockImplementation(() => {})
|
||||||
}))
|
}))
|
||||||
|
}))
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,4 +16,8 @@ export const ProcessingModes = {
|
||||||
MULTI_PROCESS: ''
|
MULTI_PROCESS: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const IOSAccessibleStates = {
|
||||||
|
AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY: ''
|
||||||
|
};
|
||||||
|
|
||||||
export const create = jest.fn();
|
export const create = jest.fn();
|
||||||
|
|
|
@ -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()
|
const MMKV = new MMKVLoader()
|
||||||
// MODES.MULTI_PROCESS = ACCESSIBLE BY APP GROUP (iOS)
|
// MODES.MULTI_PROCESS = ACCESSIBLE BY APP GROUP (iOS)
|
||||||
.setProcessingMode(ProcessingModes.MULTI_PROCESS)
|
.setProcessingMode(ProcessingModes.MULTI_PROCESS)
|
||||||
|
.setAccessibleIOS(IOSAccessibleStates.AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY)
|
||||||
.withEncryption()
|
.withEncryption()
|
||||||
.initialize();
|
.initialize();
|
||||||
|
|
||||||
|
|
|
@ -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
|
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
|
index dbea26b..2483375 100644
|
||||||
--- a/node_modules/react-native-mmkv-storage/ios/SecureStorage.m
|
--- a/node_modules/react-native-mmkv-storage/ios/SecureStorage.m
|
||||||
|
|
Loading…
Reference in New Issue