Кажется, что область не сохраняет данные между сессией или обновлением приложения - PullRequest
0 голосов
/ 26 июня 2019

В файле AppDelegate.swift в функции func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

do {
        let fileURL = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false).appendingPathComponent("main-tocca.realm")
        let realmConfig = Realm.Configuration(fileURL: fileURL, readOnly: false, schemaVersion: 4, migrationBlock: { (migration, oldSchemaVersion) in
            NSLog("\(#function) | Migration")
            if oldSchemaVersion < 4 {
                NSLog("\(#function) | Migration to version 4")
                migration.enumerateObjects(ofType: Source.className()) { (_, newSource) in
                    newSource?["fileName"] = ""
                }
            }
        }, deleteRealmIfMigrationNeeded: true, shouldCompactOnLaunch: { (totalBytes, usedBytes) -> Bool in
            // totalBytes refers to the size of the file on disk in bytes (data + free space)
            // usedBytes refers to the number of bytes used by data in the file

            // Compact if the file is over 100MB in size and less than 50% 'used'
            let oneHundredMB = 100 * 1024 * 1024
            return (totalBytes > oneHundredMB) && (Double(usedBytes) / Double(totalBytes)) < 0.5
        })

        Realm.Configuration.defaultConfiguration = realmConfig

        autoreleasepool {
            do {
                // Realm is compacted on the first open if the configuration block conditions were met.
                _ = try Realm(configuration: realmConfig)
            } catch {
                NSLog("\(#function) | Realm Error: \(error.localizedDescription)")
                SentryEventReportManager.report(err: error)
            }
        }
    } catch {
        NSLog("\(#function) | Realm File Error: \(error.localizedDescription)")
        SentryEventReportManager.report(err: error)
    }
}

Одной из самых первых операций, выполняемых приложением сразу после запуска, является доступ к локальной базе данных и поиск наличиянекоторые объекты, которые должны были сохраниться во время предыдущего использования приложения.

Используя RealmStudio, я вижу, что база данных сохраняется правильно, но при использовании на реальном устройстве я заметил, основываясь на поведении приложения, чтобаза данных может не сохраняться должным образом, поэтому при записи или чтении базы данных ошибка не возвращается (все throws правильно перехвачены)

Некоторые люди сообщали об аналогичной проблеме, и ответом было переименование default.realm файл (что я делаю), но, кажется, все еще происходит.

...