无法从Swift中的Realm对象服务器获取数据
我想使用Realm Object Server在智能手机之间共享数据,并使用Swift创建了此代码。 (我使用领域 - > 3.0.2 ROS - >最新)无法从Swift中的Realm对象服务器获取数据
let realmAuthURL = URL(string:"http://[server_address]:9080")! let realmURL = URL(string:"realm://[server_address]:9080/~/realm")!
let credentials = SyncCredentials.usernamePassword(username: "[username]", password: "[password]")
SyncUser.logIn(with: credentials, server: realmAuthURL) { user, error in
DispatchQueue.main.async {
if let user = user {
Realm.Configuration.defaultConfiguration = Realm.Configuration(
syncConfiguration: SyncConfiguration(user: user, realmURL: realmURL),
objectTypes: [PCData.self]
)
print("ログインに成功しました")
self.realm = try! Realm(configuration: Realm.Configuration.defaultConfiguration)
//print(self.realm.objects(PCData.self))
if self.realm.isEmpty {
try! self.realm.write {
let data = PCData()
data.isOut = false
data.pcCode = "***METADATA***"
data.rentPCto = ""
data.IDinCourse = 999999999999
data.belonging = "Master"
self.realm.add(data)
}
}
}
}
}
当我试了一下, “ログインに成功しました” 被输出,且服务器已被访问
似乎日志然而,
2017-12-17 22:53:30.880875+0900 PCManage[7021:1784833] Sync: Connection[1]: Connection closed due to error 2017-12-17 22:53:31.673562+0900 PCManage[7021:1784833] Sync: Connection[1]: Connected to endpoint '[Server's IP]:9080' (from '[My IP]:57032')
2017-12-17 22:53:31.684189+0900 PCManage[7021:1784833] Sync: Connection[1]: Writing failed: End of input
这是不可能得到的数据等 在服务器。
proxy: attempting to upgrade client [My IP]:57032 => headers: {"authorization":"Realm-Access-Token version=1 token=\"eyJhY2Nlc3MiOlsiZG93bmxvYWQiLCJ1cGxvYWQiLCJtYW5hZ2UiXSwiYXBwX2lkIjoiY29tLmFrYmFydC5hcHAuUVJ0ZXN0IiwiZXhwaXJlcyI6MTUxMzUxOTQwOCwiaWQiOiIwMzdmY2I5Yzc0MGE0ZjdhOGVhOTZkZmFhYjUxNmM2ZiIsImlkZW50aXR5IjoiZmI0NmQ1ZjNjYjRiNmE5NWExYWYyNDkzZGIxNjE5YzYiLCJwYXRoIjoiL2ZiNDZkNWYzY2I0YjZhOTVhMWFmMjQ5M2RiMTYxOWM2L3JlYWxtIn0=:Tn4Qa4vzvZ87lnW2htmt6rPCaLL5ASDkpqbcXT2eKskQ3NHJ3ePyMxvJjjyAq5rh8pb2syCM1Dh8LrVk9RilQsHwHRU9HyDOky/psePE4UfXidEJGYoML19R9mo+yjHPG7DeP0ykYltTjONJh+OpQkaelHYIMlKAwFP+hxeNWlVAIpjohkqmyr/de3++8IxcVV6/6wJUESdNpDq2e5GGKfxpSwbfhBagNi0m0aSNuwzoqJ5CFqbyoxsyyCZWx6XJ7ZueTmRvGx22SJcthRzxrQRrWMbMtF8yEHY/AARzycO/A/Zi5spXqAzQD6QIrkl5gGI/FwvnLvhvtPEFychXIg==\"","connection":"Upgrade","host":"[]","sec-websocket-key":"K0Tw7zhY3ov9h+VEqHtaPQ==","sec-websocket-protocol":"io.realm.sync.22","sec-websocket-version":"13","upgrade":"websocket"}.} sync: HTTP Connection[959]: Connection from 127.0.0.1:35414
sync: HTTP Connection[959]: Connection initiates HTTP receipt
sync: HTTP Connection[959]: HTTP request received, url = /realm-sync/%2Ffb46d5f3cb4b6a95a1af2493db1619c6%2Frealm
sync: HTTP Connection[959]: 404 Not Found
sync: HTTP Connection[959]: Connection is closed after HTTP response.
404未润版液显示 我认为,在服务器端,现在很奇怪,但我还没有从最初的设置更改,所以我不知道哪里错了 我怎样才能获得数据?
回答:
您共享的日志消息似乎表明您正在使用Realm Object Server v1.x. Realm Swift 3.x需要Realm Object Server v2.x.有关安装ROS v2.x的说明,请参阅Realm Object Server documentation。
以上是 无法从Swift中的Realm对象服务器获取数据 的全部内容, 来源链接: utcz.com/qa/263081.html