Search code examples
iosswiftsqlitecouchbase-lite

ios couchbase-lite replication error


i am working on a ios app, that uses the replication functionality of couchbase-lite. This replication starts on a background fetch. After a few tests on a real device, it seems to work, but when i try to start this replication on a locked device there are errors like this

Failed to Load DB 'DBNAME': Error Domain=SQLite Code=23 "authorization denied" UserInfo={NSLocalizedDescription=authorization denied}



error opening!: 23

When i start the app, i do the following to create the manager

var error:NSError?
let options:CBLManagerOptions = CBLManagerOptions(readOnly: false, fileProtection: NSDataWritingOptions.DataWritingFileProtectionCompleteUntilFirstUserAuthentication)
let poptions:UnsafePointer<CBLManagerOptions> = UnsafePointer<CBLManagerOptions>.init(UnsafeMutablePointer<CBLManagerOptions>.alloc(1).initialize(options))
manager = CBLManager(directory: CBLManager.defaultDirectory(), options: poptions, error: &error)

Any ideas how to fix this issue? This error only appears if the iphone is locked!

Thanks.


Solution

  • Problem solved, see the correct initialisation of the cblmanager below:

    var error: NSError?
    let cbloptions = CBLManagerOptions(readOnly: false, fileProtection: NSDataWritingOptions.DataWritingFileProtectionNone)
    let cblpoptions=UnsafeMutablePointer<CBLManagerOptions>.alloc(1)
    cblpoptions.initialize(cbloptions)
    manager = CBLManager(directory: CBLManager.defaultDirectory(), options: cblpoptions, error: &error)