CedricSoubrie CedricSoubrie - 3 months ago 23x
iOS Question

Access couchbase lite database directly from bundle?

I'm using Couchbase lite for my iOS app. I include the database in my app bundle and I don't have any replication. (I know it's a bit strange to use Couchbase without replication but that's the case)

The problem is that I can't find a way to access the database directly from the bundle since replaceDatabaseNamed will copy it to the document directory. As the database is huge I don't want to duplicate it on the users iPhone with one version in the bundle and one in the document directory.

Do you know a way not to copy the database and to access it directly from the app bundle ?


This works for me and successfully opens the database readonly from the bundle...

CBLManagerOptions options;
options.readOnly = YES;
_manager = [[CBLManager alloc] initWithDirectory:[[NSBundle mainBundle] resourcePath] options:&options error:&error];

if (error == nil) {
    // load an existing database
    _database = [_manager existingDatabaseNamed:named error:&error];

One thing to add here is that if you have any CBLView objects you need to make sure they get run before you save the database. They will fail to update when you are using this as a readonly database.