-decryptWithKey: gets called whether or not a key is given. If there’s no key, it just verifies that the database is useable by running a quick no-op query.
Error 14 is SQLITE_CANTOPEN, described in sqlite3.h as “Unable to open the database file”.
What’s probably going on here is that your app is running while in the background (maybe it got a push notification), but you’ve configured the app’s filesystem protection entitlement such that files cannot be opened while in the background. So SQLite fails to open the database file.
The most direct way to fix this is to set more lenient file protection options when you create the CBLManager — look at the field CBLManagerOptions.fileProtection in CBLManager.h.
We’re addressing this partly in 1.4 by improving the error handling, but the fact remains that if you want to run in the background you need to configure access to files that will be needed then.
Oh also, the reason for the crash is that you called +[CCTest modelForDocument:] and passed a nil document parameter, which is illegal. This probably happened because the database failed to open so you couldn’t read a document, but you didn’t check for errors before trying to use the (nil) CBLDocument reference.
Look at the field CBLManagerOptions.fileProtection in CBLManager.h.
You should also read the iOS docs on file protection, if you’re not familiar with it.