Skip to content

Open MMKV File Failing Due to Lack of Write Permission in iOS Keyboard Extension #1039

Description

@mfbx9da4

The language of MMKV

Objective-C & Swift

The version of MMKV

1.2.14

The platform of MMKV

iOS

The installation of MMKV

Cocoapods

What's the issue?

I am building an iOS Keyboard Extension. The keyboard does not require OpenAccess, meaning the app extension does not have write capabilities. Initialization of MMKV is failing because it opens the file with read & write. Is it possible to configure a read-only mode?

[I] <MMKV.cpp:207::initializeMMKV> root dir: /var/mobile/Containers/Data/PluginKitPlugin/348876A7-DA00-425D-A17A-927902D2B39C/Documents/mmkv
[I] <libMMKV.mm:115::+[MMKV initializeMMKV:groupDir:logLevel:]> 
groupDir: 
/private/var/mobile/Containers/Shared/AppGroup/307129F1-4DB2-4AC3-B519-4D29E8FA9F3C/mmkv
[D] <libMMKV.mm:721::+[MMKV mmapKeyWithMMapID:rootPath:]> mmapKey: 893c7e6db2d602f7ff1df4cf29ac1b50
[I] <MMKV.cpp:234::mmkvWithID> prepare to load default.mmkv (id 893c7e6db2d602f7ff1df4cf29ac1b50) from rootPath /private/var/mobile/Containers/Shared/AppGroup/307129F1-4DB2-4AC3-B519-4D29E8FA9F3C/mmkv
[E] <MemoryFile.cpp:94::open> fail to open [/private/var/mobile/Containers/Shared/AppGroup/307129F1-4DB2-4AC3-B519-4D29E8FA9F3C/mmkv/default.mmkv], 1(Operation not permitted)
[E] <MemoryFile.cpp:94::open> fail to open [/private/var/mobile/Containers/Shared/AppGroup/307129F1-4DB2-4AC3-B519-4D29E8FA9F3C/mmkv/default.mmkv], 1(Operation not permitted)
[E] <MemoryFile.cpp:208::reloadFromFile> fail to open:/private/var/mobile/Containers/Shared/AppGroup/307129F1-4DB2-4AC3-B519-4D29E8FA9F3C/mmkv/default.mmkv, Undefined error: 0
[E] <MemoryFile.cpp:94::open> fail to open [/private/var/mobile/Containers/Shared/AppGroup/307129F1-4DB2-4AC3-B519-4D29E8FA9F3C/mmkv/default.mmkv.crc], 1(Operation not permitted)
[E] <MemoryFile.cpp:94::open> fail to open [/private/var/mobile/Containers/Shared/AppGroup/307129F1-4DB2-4AC3-B519-4D29E8FA9F3C/mmkv/default.mmkv.crc], 1(Operation not permitted)
[E] <MemoryFile.cpp:208::reloadFromFile> fail to open:/private/var/mobile/Containers/Shared/AppGroup/307129F1-4DB2-4AC3-B519-4D29E8FA9F3C/mmkv/default.mmkv.crc, Undefined error: 0
[E] <MemoryFile.cpp:94::open> fail to open [/private/var/mobile/Containers/Shared/AppGroup/307129F1-4DB2-4AC3-B519-4D29E8FA9F3C/mmkv/default.mmkv], 1(Operation not permitted)
[E] <MemoryFile.cpp:208::reloadFromFile> fail to open:/private/var/mobile/Containers/Shared/AppGroup/307129F1-4DB2-4AC3-B519-4D29E8FA9F3C/mmkv/default.mmkv, Undefined error: 0
[E] <MMKV_IO.cpp:74::loadFromFile> file [/private/var/mobile/Containers/Shared/AppGroup/307129F1-4DB2-4AC3-B519-4D29E8FA9F3C/mmkv/default.mmkv] not valid

I've "fixed" this by changing MemoryFile.cpp:94 from

m_fd = ::open(m_path.c_str(), OpenFlag2NativeFlag(m_flag), S_IRWXU);

to

m_fd = ::open(m_path.c_str(), O_RDONLY);

and MemoryFile.cpp:188 from

m_ptr = (char *) ::mmap(m_ptr, m_size, PROT_READ | PROT_WRITE, MAP_SHARED, m_diskFile.m_fd, 0);

to

m_ptr = (char *) ::mmap(m_ptr, m_size, PROT_READ, MAP_SHARED, m_diskFile.m_fd, 0);

Activity

  1. changed the title [-]Read-only mode failing in iOS keyboard extension[/-] [+]Open file failing due to lack of write permission in iOS keyboard extension [/+] on Mar 20, 2023
  2. changed the title [-]Open file failing due to lack of write permission in iOS keyboard extension [/-] [+]Open MMKV file failing due to lack of write permission in iOS keyboard extension [/+] on Mar 20, 2023
  3. lingol commented on Mar 22, 2023

    @lingol
    Collaborator

    Why would you create a read-only MMKV instance? It provides little functionality.

  4. mfbx9da4 commented on Mar 22, 2023

    @mfbx9da4
    Author

    A read-only MMKV instance is needed if you would like to display data from the main app in the keyboard extension.

    For example, the user has logged in and created some todo items in the main app. The keyboard extension may want to display that the user is logged in or is required to log in and list those todo items.

  5. changed the title [-]Open MMKV file failing due to lack of write permission in iOS keyboard extension [/-] [+]Open MMKV File Failing Due to Lack of Write Permission in iOS Keyboard Extension[/+] on Mar 22, 2023
  6. locked and limited conversation to collaborators on Mar 22, 2023
  7. converted this issue into a discussion #1043 on Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions