CoreData errors/exceptions when app work in background mode

牧云@^-^@ 提交于 2019-12-08 08:32:56

问题


I'm doing a multithreaded CoreBluetooth app where the iPhone is working as a central, scanning (based on UI-interaction) for peripherals which then are connected and processed, resulting in various changes to the app's CoreData model used to store persistent info on the state of the different peripherals that the user has access to (without having to connected to them every time the user starts the app).

The user basically request connection to a peripheral via the UI, which then kick an async worker thread that will try to accomplish the request within a certain time-frame (e.g., a few minutes), else reporting a failure/timeout back to the UI.

Everything is working fine, but I just now started to add support for background execution since it's very likely that the users will start the async worked thread that will start to scan for BLE-peripherals, and then lock the phone and place in their pockets, expecting things to work when the peripheral is within reach.

However, Bluetooth-wise things work as they should (peripheral is discovered, connected, and processed), but I suddenly get CoreData exceptions;

CoreData: error: exception during newFetchedPKsForSourceID: I/O error for database at /var/mobile/Applications/8640B48D-8744-436A-A083-C39F63FBFB3F/Documents/Model.sqlite.  SQLite error code:266, 'not an error' errno:1 with userInfo of {
    NSFilePath = "/var/mobile/Applications/8640B48D-8744-436A-A083-C39F63FBFB3F/Documents/Model.sqlite";
    NSPOSIXErrorDomain = 1;
    NSSQLiteErrorDomain = 266;
}

CoreData: error: exception during newFetchedPKsForSourceID: authorization denied with userInfo of {
    NSFilePath = "/var/mobile/Applications/8640B48D-8744-436A-A083-C39F63FBFB3F/Documents/Model.sqlite";
    NSSQLiteErrorDomain = 23;
}

CoreData: error: exception during newFetchedPKsForSourceID: authorization denied with userInfo of {
    NSFilePath = "/var/mobile/Applications/8640B48D-8744-436A-A083-C39F63FBFB3F/Documents/Model.sqlite";
    NSSQLiteErrorDomain = 23;
}

CoreData: error: exception during newFetchedPKsForSourceID: authorization denied with userInfo of {
    NSFilePath = "/var/mobile/Applications/8640B48D-8744-436A-A083-C39F63FBFB3F/Documents/Model.sqlite";
    NSSQLiteErrorDomain = 23;
}

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'I/O error for database at /var/mobile/Applications/8640B48D-8744-436A-A083-C39F63FBFB3F/Documents/Model.sqlite.  SQLite error code:266, 'not an error' errno:1'

So, in short; all's good as long as I don't put the app in background execution mode, which to me indicate that threading and sync/merge/CoreData issues are properly setup. But something changes when the app goes into background...

Looking forward to your thoughts and ideas,

/Markus

来源:https://stackoverflow.com/questions/22038976/coredata-errors-exceptions-when-app-work-in-background-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!