4

我在 Crashlytics 报告工具中遇到下一个错误:

致命错误:未解决的错误错误域=NSCocoaErrorDomain 代码=256“无法打开文件“xxxx.sqlite”。” UserInfo={NSFilePath=/var/mobile/Containers/Data/Application/yyyy/Library/Application Support/xxxx.sqlite, NSSQLiteErrorDomain=23}, ["NSSQLiteErrorDomain": 23, "NSFilePath": /var/mobile/Containers/ Data/Application/yyyy/Library/Application Support/xxxx.sqlite]:文件 /xxxx/AppDelegate.swift,第 171 行

此错误仅出现在 iOS 13.3.0 上。在早期版本中,它工作正常。我无法在我的网站上重现它,并且出现此错误的用户正在增加。

这是我在 AppDelegate.swift 文件中的代码:

import CoreData
import Firebase

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, WebServerDelegate {

    var window: UIWindow?

    // Override point for customization after application launch.
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        DLog(className: String(describing: self), message: "")

        FirebaseApp.configure()
        Fabric.with([Crashlytics.self])

        let storageController = StorageController(managedContext: self.persistentContainer.viewContext)

        /* 
         * Other code ...
         */
        return true
    }

    /* 
     * Other delegate methods ...
     */

    // MARK: - Core Data stack
    lazy var persistentContainer: NSPersistentContainer = {
        let container = NSPersistentContainer(name: "xxxx")
        container.loadPersistentStores(completionHandler: { (storeDescription, error) in
            if let error = error as NSError? {
                fatalError("Unresolved error \(error), \(error.userInfo)")
            }
        })
        return container
    }()

    // MARK: - Core Data Saving support
    func saveContext () {
        let context = persistentContainer.viewContext
        if context.hasChanges {
            do {
                try context.save()
            } catch {
                let nserror = error as NSError
                fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
            }
        }
    }
}

根据 Crashlytics 的说法,错误是:container.loadPersistentStores... 它是 iOS 13.3.0 的错误还是 CoreData 的错误实现?你知道问题出在哪里吗?

谢谢!

4

0 回答 0