Tencent / MMKV

An efficient, small mobile key-value storage framework developed by WeChat. Works on Android, iOS, macOS, Windows, and POSIX.
Other
17.39k stars 1.91k forks source link

Fix multiprocess mode on iOS #1221

Closed maxencehenneron closed 9 months ago

maxencehenneron commented 9 months ago

There is currently no way to enable multiprocess mode on iOS. I was initializing MMKV using the following code (Swift):

Screenshot 2024-01-03 at 11 46 34 AM

Yet, the logs would display the following:

loading [mmkv.default] with 0 actual size, file size 16384, InterProcess 0, meta info version:4

Looking at the source code, I found the constructor associated with this class here:

https://github.com/Tencent/MMKV/blob/master/iOS/MMKV/MMKV/libMMKV.mm#L181-L184

this constructor sets rootPath to g_groupPath if mode is not MMKVSingleProcess and calls another (private) constructor

[MMKV mmkvWithID:mmapID cryptKey:cryptKey rootPath:rootPath mode:mode]

Unfortunately, this constructor forces the mode to MMKVSingleProcess, it also does not implement relativePath so the comment isn't relevant anymore.

https://github.com/Tencent/MMKV/blob/master/iOS/MMKV/MMKV/libMMKV.mm#L212

Also there does not seem to be any constructor that let you set both "mode" and "relativePath" anymore so the comment is really not needed.

Looking at all the exported constructors, none of them let you set multi-process mode as they all end up calling the constructor that forces MMKVSingleProcess so I don't think there is currently a way to enable multi-process mode on iOS. I would like to enable this mode mainly for sharing data with my iOS widgets.

tencent-adm commented 9 months ago

CLA assistant check
All committers have signed the CLA.