Getting CBL working whiles app is backgrounded (...fileProtection modes)

30 views
Skip to first unread message

Nick Pomfret

unread,
Sep 28, 2016, 5:34:41 AM9/28/16
to Couchbase Mobile
I'm trying to get a react-native app working with background fetch and on push notifications - basically when its working in the background.


I understand there's a need to adjust the file permissions (maybe to pass in here?).  But I'm no iOS programmer and so am a bit stuck.  Any advice?

Jens Alfke

unread,
Sep 28, 2016, 11:01:43 AM9/28/16
to mobile-c...@googlegroups.com

On Sep 28, 2016, at 2:34 AM, Nick Pomfret <npom...@gmail.com> wrote:

I understand there's a need to adjust the file permissions (maybe to pass in here?).  But I'm no iOS programmer and so am a bit stuck.  Any advice?

You’ll need to initialize the Manager object like so, instead of using the sharedInstance:

    CBLManagerOptions options = {NO, NSDataWritingFileProtectionCompleteUntilFirstUserAuthentication};
    NSError* error;
    CBLManager *mgr = [[CBLManager alloc] initWithDirectory: [CBLManager defaultDirectory]
                                                    options: &_options error: &error];

This changes the file protection mode of the database files such that they can still be opened by the app after the device is locked.

—Jens

Jens Alfke

unread,
Sep 28, 2016, 11:24:16 AM9/28/16
to mobile-c...@googlegroups.com
…and I forgot to note that ‘mgr’ needs to be either a static or global variable, or an instance variable of the app delegate. If it’s just a local variable, it will be released when that method exits, which I think would dealloc the Manager.

—Jens

Nick Pomfret

unread,
Sep 28, 2016, 12:12:31 PM9/28/16
to Couchbase Mobile
Thanks Jens. I owe you a beer!
Reply all
Reply to author
Forward
0 new messages