I’m having trouble understanding sync in CBL iOS. I’m using v1.4 and created a local database, a puller and a pusher, I set both to continuous and added the sync url. It seems that it syncs but I have no idea where the documents go. My sync url returns a json like this:
"committed_update_seq": 548,
"compact_running": false,
"db_name": "beaconio",
"disk_format_version": 0,
"instance_start_time": 1489597104736843,
"purge_seq": 0,
"state": "Online",
"update_seq": 548
}```
And my code goes like this:
private static var SYNC_URL = URL.init(string: "MySyncUrl")
private static var DEFAULT_DB_NAME = "test"
private var database: CBLDatabase!
private var puller: CBLReplication!
private var pusher: CBLReplication!
private var syncError: NSError!
private var dbName: String!
private var lEncrypt = true
init () {
dbName = CouchbaseObservable.DEFAULT_DB_NAME
let dbOptions = CBLDatabaseOptions()
dbOptions.create = true
if(lEncrypt) {
dbOptions.encryptionKey = "foo"
}
do {
try database = CBLManager.sharedInstance().openDatabaseNamed(dbName, with: dbOptions)
} catch {
print("Error while opening the db")
}
}
public func closeDatabase() throws {
try database.close()
}
public func createDocument() -> CBLDocument {
return database.createDocument()
}
public func getDocument(docId: String) -> CBLDocument? {
return database.existingDocument(withID: docId)
}
public func startSync() {
if database == nil {
return
}
let url = CouchbaseObservable.SYNC_URL!
pusher = database.createPushReplication(url)
pusher.continuous = true // Runs forever in background
NotificationCenter.default.addObserver(self, selector: #selector(replicationProgress(notification:)),
name: NSNotification.Name.cblReplicationChange, object: pusher)
puller = database.createPullReplication(url)
puller.continuous = true // Runs forever in background
NotificationCenter.default.addObserver(self, selector: #selector(replicationProgress(notification:)),
name: NSNotification.Name.cblReplicationChange, object: puller)
var auth: CBLAuthenticatorProtocol?
auth = CBLAuthenticator.basicAuthenticator(withName: "test", password: "foo")
pusher.authenticator = auth
puller.authenticator = auth
pusher.start()
puller.start()
}
But how do I get that json? Where is it stored? What method should I call to get it? I'm thinking maybe in the listener doing something like the following but I still don't get exactly **what** I should do there.
@objc func replicationProgress(notification: NSNotification) {
if pusher.status == .active || pusher.status == .stopped {
// do something
}
if puller.status == .active || puller.status == .stopped {
// do something
}
}