Reputation: 49
we are working on implementing CBLite continuous replicator in our IOS app and one of the requirement is to support background mode. The replicator should stay active when app goes into background state and sync data.
We used BGProcessingTaskRequest
to get more execution time for long running task, but it seems like replicator never completes the sync it fetches document for some time when in background and then stops syncing. It's not even printing other states like (idle, connecting,offline,Stopped).
But, if I move app from background to foreground it resumes the sync from last state and completes it. I thought BGProcessingTaskRequest
can be used to complete long running task, is that not the case?
I have enabled below properties on replicator.
replicator.allowReplicatingInBackground = true
.replicator.continuous = true
replicator.replicatorType = "pushAndPull"
Upvotes: 0
Views: 98
Reputation: 2167
I'm actually looking into something similar at the moment, except that in my case the important part is making sure blobs in the local db can be synced to the server in the background.
I've read through a bunch of docs/blog posts/tutorials from Couchbase (which are all pretty outdated now) and it seems that the best practice for syncing in the background is to do a "one-shot replication".
This seems to mean that you should set replicator.continuous = false
. In all of their examples they also only use replicator.replicatorType = .pull
so maybe .pushAndPull
is not supported for "one-shot replication"?
Either way, since the system will only give your app limited time to run things in the background, regardless of background task type, it doesn't make sense to have a continuous replicator running.
You are probably better off having your continuous replicator in the foreground, then in the background running a one-shot replication. When returning to the foreground you'd just go back to running your continuous replicator.
Upvotes: 0
Reputation: 86
I'm not quite sure if BGProcessingTaskRequest can be used for extending the app to run in the background. From this doc, it seems to be fore launching and using the app in the background.
For extending the app to continue to run in the background, you may look into this doc.
I haven't worked on the iOS app for awhile so I might be wrong and outdated.
Upvotes: 0