Couchbase无法连接到同步网关,也找不到iOS应用程序的同步网关的配置文件?

时间:2018-07-30 07:39:09

标签: swift couchbase-lite couchbase-sync-gateway

override func viewDidLoad() {
    super.viewDidLoad()

    let database:Database

    // get the data base if its doesent exsist create one
    do {
        database = try Database(name: "my_db")
    }
    catch{
        fatalError("Error opening database")
    }


    // Create a new document (i.e. a record) in the database.
    let mutableDoc = MutableDocument()
    .setFloat(2.0, forKey: "Version")
    .setString("SDK", forKey: "type")

    // Save it to the database.
    do {
        try database.saveDocument(mutableDoc)
    } catch {
        fatalError("Error saving document")
    }

    // Create replicators to push and pull changes to and from the cloud.
    let targetEndpoint = URLEndpoint(url: URL(string: "ws://localhost:4984/my_db")!)
    let replConfig = ReplicatorConfiguration(database: database, target: targetEndpoint)
    replConfig.replicatorType = .pushAndPull

    // Add authentication.
    replConfig.authenticator = BasicAuthenticator(username: "john", password: "pass")

    // Create replicator.
    let replicator = Replicator(config: replConfig)

    // Listen to replicator change events.
    replicator.addChangeListener { (change) in
        if let error = change.status.error as NSError? {
            print("Error code :: \(error.code)")
        }
    }

    // Start replication.
    replicator.start()
}

除此代码外,我还在后台运行同步网关。我还将附加终端响应。

2018-07-30T12:50:05.116+05:30 HTTP: #001:     --> 404 no such database    "example_sg_db"  (0.2 ms)
2018-07-30T12:57:57.215+05:30 HTTP:  #002: GET /my_db/_blipsync (as )
2018-07-30T12:57:57.215+05:30 HTTP: #002:     --> 404 no such database "my_db"  (0.1 ms)

我尝试了网页中给出的解决方案,但没有给出正确的解释。

0 个答案:

没有答案