iOS 崩溃:无法在路径打开领域

iOS crash : Unable to open a realm at Path

我在 Crashlytics 上看到了一些崩溃,但无法重现应用启动时发生的崩溃。有谁知道如何重现以下崩溃。我已经尝试了 Github 和 Whosebug 上的所有答案,但没有人提到重现此特定崩溃。 因此,如果我确实有修复程序,除了将修复程序投入生产然后假设 Crashlytics 不会显示崩溃之外,没有其他方法可以测试它。

请帮忙。

错误:

Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=2 "Unable to open a realm at path '/var/mobile/Containers/Data/Application/03BA7C37-9852-4A01-8EF6-949E308EADCD/Documents/default.realm.lock': open() failed: Operation not permitted." UserInfo={Error Code=2, NSFilePath=/var/mobile/Containers/Data/Application/03BA7C37-9852-4A01-8EF6-949E308EADCD/Documents/default.realm.lock,

调用代码

//passing the fileProtectionType as .none
RealmHelper.configureRealmFiles(with: .none)

示例代码

   static func configureRealmFiles(with fileProtectionType: FileProtectionType) {
            guard let folderPath = realm.configuration.fileURL?.deletingLastPathComponent().path else {
                return
            }

            do {
                try FileManager.default.setAttributes([FileAttributeKey.protectionKey: fileProtectionType],
                                                      ofItemAtPath: folderPath)
            } catch {
                logI("Realm: Couldn't change Realm file protection type")
            }
        }

Realm documentation 有一些关于如何处理这个错误的信息。检查他们关于降级文件访问属性的说明是否适合您的情况。

在新位置添加 default.realm.lock 成功并阻止了崩溃再次出现。但是我永远无法复制崩溃。这是因为它可能在后台发生。

从项目中删除 realm pod 并重新安装它对我很有帮助:)