CouchbaseLite Code=16 “Cannot close the database. Please stop all of the replicators before closing the database.” UserInfo={NSLocalizedFailureReason=Cannot close the database. Please stop all of the replicators before closing the database., NSLocalizedDescription=Cannot close the database. Please stop all of the replicators before closing the database.}**
the code to stop the replicator is as follow :
func stopAllReplicationForCurrentUser() {
if let ltoken = listenerToken{
replicator.removeChangeListener(withToken: ltoken)
replicator.stop()
}
if let uLtoken = userListenerToken{
userReplicator.removeChangeListener(withToken: uLtoken)
userReplicator.stop()
}
}
I am calling all replicator to stop but still i am getting the same issue .
As Jens already mentioned in his post, please wait for the replicator to stop and you can do this by verifying for the status specified through the listener .
well thanks for your response , but i tried it and found one java code where it says , need to wait and using timer it do the stuff but in ios its not working , got stuck in same issue , could you help us on this.
First up all, remove all your liveQuery Listeners and then call stop replicator method.
Here is the small snippet of your replication Changelistener.
listener_token = self.replicator?.addChangeListener({ (change) in
if change.status.activity == .stopped{
NotificationCenter.default.post(name: .didCouchbaseStop, object: nil, userInfo: nil)
}
})
Handle notification method in your ViewController and then redirect to rootViewController.
as Jens mentioned early. it is asynchronous, so you need to rotate a spinner until replication stopped.
I tried this way and current status says it gets stopped but after that when i call database.delete() and database.close() , it says : CouchbaseLite Code=16 “Cannot delete the database. Please remove all of the query listeners before deleting the database.” UserInfo={NSLocalizedFailureReason=Cannot delete the database. Please remove all of the query listeners before deleting the database., NSLocalizedDescription=Cannot delete the database. Please remove all of the query listeners before deleting the database.}
could anyone help me on this ? ( cblite 2.1 version currently i am using)
inside addchangelistener i got information about change.status == stopped , then only i am deleting the couchbase lite file , but it again saying the same thing
Use a breakpoint or a print statement or something to verify that the listener was actually removed. That error message means you didn’t remove all query listeners.
Also be sure that if you overwrite listenerToken1 with something else, that you either save the original value somewhere or remove it then. Each call to addChangeListener needs a remove call later using the token it generated.
I am storing listenertoken ( document listener ) into model and whenever i don’t need , just remove it , whether frequently removing listener token does any impact ( any chance on crash ) ? ,