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();
export const useUserPreferences = create(MMKV);
class UserPreferences {
private mmkv: MMKVInstance;
constructor() {
this.mmkv = MMKV;
}
getString(key: string): string | null {
try {
return this.mmkv.getString(key) ?? null;
} catch {
return null;
setString(key: string, value: string): boolean | undefined {
return this.mmkv.setString(key, value) ?? undefined;
getBool(key: string): boolean | null {
console.log(this.mmkv.getBool(key));
return this.mmkv.getBool(key) ?? null;
setBool(key: string, value: boolean): boolean | undefined {
return this.mmkv.setBool(key, value) ?? undefined;
getMap(key: string): object | null {
return this.mmkv.getMap(key) ?? null;
setMap(key: string, value: object): boolean | undefined {
return this.mmkv.setMap(key, value) ?? undefined;
removeItem(key: string): boolean | undefined {
return this.mmkv.removeItem(key) ?? undefined;
const userPreferences = new UserPreferences();
export default userPreferences;