Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Getting CBL iOS working in the background #90

Open
npomfret opened this issue Sep 28, 2016 · 10 comments
Open

Getting CBL iOS working in the background #90

npomfret opened this issue Sep 28, 2016 · 10 comments

Comments

@npomfret
Copy link
Contributor

npomfret commented Sep 28, 2016

I'm seeing lots of errors when my app is backgrounded. It seems that after a while neither background fetch or push notifications adequately wake the app up. I understand that the solution might be to set the file protection mode. But I don't really understand how to do this. I tried making the following change (a completed guess) to ReactCBLite.m

        //CBLManager* dbmgr = [CBLManager sharedInstance];
        NSString* dir = [CBLManager defaultDirectory];
        CBLManagerOptions options = {};
        options.fileProtection = NSDataWritingFileProtectionCompleteUntilFirstUserAuthentication;
        NSError* error;
        CBLManager* dbmgr =   [[CBLManager alloc] initWithDirectory: dir options: &options error: &error];

But it didn't work. My databases aren't available to the listener. Any ideas?

@npomfret
Copy link
Contributor Author

@yonahforst @jamiltz - i may have answered my own question here. It not tested properly yet, but after a bit scratching around for a solution I was advised to change the CBLManagerOptions and set fileProtection. Here's the change on my fork npomfret@d67b48b
.

If it works, is this something we want in master? I'm hoping it will allow the app to remain responsive while backgrounded for long periods of time. At the moment it seems to work for a bit when backgrounded, but after a while my push notification seem to stop working.

If we do put it in, should it be the default? Or should it be configurable from JS code?

couchbase/couchbase-lite-ios#1405 (comment)

https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/mobile-couchbase/X9TIHtNTf1Y/l9TzPwmAAAAJ

https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/StrategiesforImplementingYourApp/StrategiesforImplementingYourApp.html

@npomfret
Copy link
Contributor Author

npomfret commented Oct 9, 2016

Any chance you guys could upvote couchbase/couchbase-lite-ios#1410 (not sure it will help but worth a try!)

@npomfret
Copy link
Contributor Author

@yonahforst @jamiltz - any thoughts on this? I've been using the suggested CBLManagerOptions for a couple of weeks now and they seem to be working well.

Is this something we should add to master?

@danlannz
Copy link
Contributor

hey guys, any update / workaround for this? I'm experiencing what seems like the same issue on iOS.

Once the device is backgrounded then reopened again React Native can no longer access the local database with an error like [Error: Request has been terminated Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.]

The weirdest thing is that it works fine in the Simulator, it's only when run on a device that the issue occurs

@danlannz
Copy link
Contributor

@npomfret I implemented your suggested changes to ReactCBLite.m and ReactCBLite.h but it still doesn't seem to work

@npomfret
Copy link
Contributor Author

npomfret commented Aug 17, 2017

What did you implement? The options.fileProtection stuff?

@danlannz
Copy link
Contributor

yea exactly, just this patch npomfret@d67b48b

@danlannz
Copy link
Contributor

got to the bottom of it, was related to your couchbase/couchbase-lite-ios#1410 @npomfret

added a react native AppState event listener to control the Couchbase listener's state Keepsite@e3722be, is this something useful to others? can open a PR if so

@jamesnocentini
Copy link
Contributor

Awesome work! 👍 It looks like there are two patches here so 2 different PRs.

Keepsite@e3722be makes total sense. @danlannz if you could open a PR to master and assign it to me that would be great.

Regarding npomfret@d67b48b, not sure what it is trying to fix because I haven't read much on the file protection options. If someone can explain it again (sorry if I missed an earlier comment) that would be great.

@danlannz
Copy link
Contributor

cheers @jamiltz just opened three PR's, one is from https://github.com/EthanRTF/react-native-couchbase-lite to update CBL dependency for android
these PR's probably relate to #103 also

re. npomfret/react-native-couchbase-lite@d67b48b @snej recommends it here, I didn't test it enough to confirm the iOS locked behaviour but I trust it makes a difference

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants