iOS 14+ 中的 Swift Realm 问题

Aur*_*ura 9 realm swift ios14

------LE:我们最终删除了数据库的加密,因为根据领域团队的建议,情况变得更糟 - 我们所能做的就是删除数据库并丢失所有存储的信息。现在我们只在钥匙串中加密我们需要的字段。------

我在商店发布了一个应用程序,在将他们的 iOS 版本更新到 14+ 后,用户开始抱怨没有从数据库中填充信息。并非所有 iOS 14+ 用户都有此问题,它会在某些设备上随机出现。

如果他们重新安装应用程序或将其更新到另一个版本后,问题会消失一段时间,但在使用它几分钟后又会再次发生。

我的数据库使用此处记录的加密。

我的应用程序的商店版本使用 Realm 5.4.8,但我测试了他们的最新版本 (10.0.0),但问题仍然存在。

我检查了这个问题,但对我来说不是这样,我没有共享的应用程序组容器或共享扩展。

以下是 Realm 的初始化方式:

override init() {
    super.init()

    do {
        guard let config = getMigrationAndEncryptionConfiguration() else {
            realmConfigured = try Realm()
            return
        }
        realmConfigured = try Realm(configuration: config)
    } catch let error as NSError {
        // this is where I got the error:
        //"Encrypted interprocess sharing is currently unsupported.DB has been opened by pid: 4848. Current pid is 5806."
    }
}

func getMigrationAndEncryptionConfiguration() -> Realm.Configuration? {
    let currentSchemaVersion: UInt64 = 19
    
    if Keychain.getData(for: .realmEncryptionKey) == nil {
        var key = Data(count: 64)
        _ = key.withUnsafeMutableBytes { bytes in
            SecRandomCopyBytes(kSecRandomDefault, 64, bytes)
        }
        Keychain.save(data: key, for: .realmEncryptionKey)
    }
    
    guard let key = Keychain.getData(for: .realmEncryptionKey) else {
        return nil
    }

    let fileUrl = Realm.Configuration().fileURL!.deletingLastPathComponent()
        .appendingPathComponent("Explorer.realm")
    
    var config = Realm.Configuration(fileURL: fileUrl,
                                     encryptionKey: key,
                                     schemaVersion: currentSchemaVersion, migrationBlock: { (migration, oldVersion) in
                                        if oldVersion != currentSchemaVersion {
                                            print("we need migration!")
                                        }
    })
    
    return config
}
Run Code Online (Sandbox Code Playgroud)

我在 SO 上为同一问题打开了另一个问题,但由于我没有足够的详细信息,它已关闭。在我的应用程序发布另一个带有更多日志的版本后,我可以找到初始化领域时出现的错误:

“目前不支持加密的进程间共享。数据库已被pid打开:4848。当前pid为5806。”

这在应用程序进入后台后出现,它被终止(系统/用户崩溃或关闭),当用户再次打开它时,领域无法初始化。

我阅读了有关应用程序组或共享扩展中不支持加密领域的所有信息,但我没有在我的应用程序中实现任何这些,是否还有其他原因导致此错误发生?

我还从我的应用程序中删除了 Firebase Performance,因为我读到这个模块可能会在领域数据库上产生问题,但它没有帮助。

我在领域 github 页面上打开了一个问题,但我还没有得到答案。

有谁知道如何解决这个问题或为什么会这样?

谢谢你。