Skip to content

How to use react-native-mmkv v3 with custom native code #808

Open
@roni-castro-shipt

Description

@roni-castro-shipt

Description

I currently use MMKV for obtaining an anonymous ID from storage on both Android and iOS in a React Native app (version 0.75.5). The code snippet below initializes MMKV and retrieves a string value:

#import <MMKV/MMKV.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   [MMKV initializeMMKV:nil];
   MMKV *mmkv = [MMKV defaultMMKV];
   NSString *userInfo = [mmkv getStringForKey:storageKey];
   // do some stuff with that userInfo, and this works as expected when using the Xcode debugger
  ...
}
  • I've set ENV['RCT_NEW_ARCH_ENABLED'] = '1'
  • I'm on React Native version 0.75.5.
  • I don't have use_frameworks in my ios/Podfile.

After updating MMKV to version from 2.11.0 to 3.2.0, I encountered an error indicating that #import <MMKV/MMKV.h> could not be found, as it seems the native peer dependency for MMKV was removed in this latest version.

Image

To fix this, I tried manually adding the MMKV pod to my Podfile like so:

pod 'MMKV', "1.2.13"

Question:

For this version of the library (MMKV 3.2.0), why do I need to manually add the MMKV pod instead of relying on autolinking?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions