Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app groups: value undefined until restart #622

Open
coopermaruyama opened this issue Jan 16, 2024 · 4 comments
Open

app groups: value undefined until restart #622

coopermaruyama opened this issue Jan 16, 2024 · 4 comments

Comments

@coopermaruyama
Copy link

I'm using this to share data between a share extension and a react native app and noticing an issues that is pretty easily reproducible.

Observed behavior (when react native app is closed):

  • call set('key','value') on extension
  • open app
  • call get('key') , returns 'value' (works as expected).

Observed behavior (when app is backgrounded):

  • call set('key','value') on extension
  • open app
  • call get('key') , returns undefined (unexpected).
  • at this point, if I close the app, and then reopen it, a call to get('key') now returns 'value'

So the value is indeed being written correctly to the shared container, however the app can only read it after a restart, which leads me to believe that the initialization code is a requirement in order to get the right value.

@mrousavy
Copy link
Owner

Did you add AppGroup to Info.plist?

NSString* appGroup = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"AppGroup"];
if (appGroup == nil) {
[MMKV initializeMMKV:storageDirectory];
} else {
NSString* groupDir = [[NSFileManager defaultManager]
containerURLForSecurityApplicationGroupIdentifier:appGroup]
.path;
[MMKV initializeMMKV:nil groupDir:groupDir logLevel:MMKVLogNone];
}

@coopermaruyama
Copy link
Author

of course. If the app groups were not correctly set up, there would be no case where I can share values between the app and the extension. It indeed works, but the issue here is that, it is not readable by the 'other side' until that app is restarted. hope that makes sense..

I'm going to try modifying the library such that the initialization code re-runs when the app state goes background -> foreground. If this fixes the issue then it would confirm my suspicion that there is some dependency on that code running in order for the values to be updated on the other side.

@mrousavy
Copy link
Owner

Okay so the MMKV instance gets created with AppGroups... idk

@nmalzieu
Copy link

nmalzieu commented Jan 22, 2024

I can confirm I started having issues with data being stale in my ios extension.

Have been using AppGroups with MultiProcess mode for 6+months without any issue.

Recently upgraded to Expo 50 & RN 0.73, not sure if that's linked, but now my extension often reads stale data, and sometimes logs InvalidProtocolBuffer truncatedMessage

There seems to be recent iOS multiprocess PRs on the MMKV repo but I tried pinning the MMKV version to the latest 1.3.2 and no luck

Tencent/MMKV#1222

EDIT : looking more closely, it seems that

  • the error from the PR above fixes an issue that was introduced in 1.3.2. PR has been merged 3 weeks ago but no new version has been released
  • v1.3.1 from releases https://github.com/Tencent/MMKV/releases/tag/v1.3.1 says it was fixing "a critical bug that might cause multi-process MMKV corrupt" introduced in v1.2.16

So right now iOS devs might want to wait for the next release or pin the MMKV iOS version to 1.3.1. I guess my issues are not due to Expo 50 / RN upgrade but to the fact that I upgraded many libs during that big upgrade and might have upgraded MMKV at the same time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants