gpt4 book ai didi

ios - Realm 对象服务器创建数据库和 ROS 但不同步

转载 作者:搜寻专家 更新时间:2023-11-01 07:17:57 26 4
gpt4 key购买 nike

我已经在 AWS (RHAT) 上设置了一个 Realm Object Server,它似乎运行良好。我可以查看仪表板,它会告诉我有多少个连接以及多少个 Realm 在端口 9080 上打开。我的代码在设备上运行良好,更新正在设备 Realm 上发生。但我没有看到 ROS Realm 有任何变化。我可能犯了一些非常基本的错误,但我说不出是什么。

func setupRealm() {
// Authenticating the User
let username = "exampleuser"
let password = "examplepassword"
SyncUser.logInWithCredentials(SyncCredentials.usernamePassword(username, password: password), authServerURL: NSURL(string: "http://example.com:9080")!, onCompletion:
{ user, error in
if let user = user {
// Opening a remote Realm
let realmURL = NSURL(string: "realm://example.com:9080/~/VWF3")!
let config = Realm.Configuration(syncConfiguration: SyncConfiguration(user: user, realmURL: realmURL))
let realm = try! Realm(configuration: config)
// Any changes made to this Realm will be synced across all devices!
} else if let error = error {
// handle error
}
})
}

我从 ViewDidLoad 调用 setupRealm()。

我的开发人员需要能够看到 ROS Realm 的变化,以确保一切正常工作,但那里只有单个用户 Realm ,表结构准确,数据为零。

我检查了服务器上的日志文件,没有发现任何异常。

马特

最佳答案

您需要确保在进行写入时仍然指的是特定的 Realm(及其同步配置)。如果您尝试写入 让 realm = try! Realm() 即使在这次登录之后,您仍然会引用您的默认 Realm,它是不同步的。

如果你打算让你的整个应用程序同步,你可以将特定的 Configuration 设置为你的默认 Realm:

if let user = user {
// Opening a remote Realm
let realmURL = NSURL(string: "realm://example.com:9080/~/VWF3")!
let config = Realm.Configuration(syncConfiguration: SyncConfiguration(user: user, realmURL: realmURL))
Realm.Configuration.defaultConfiguration = configuration
// All calls to `Realm()` will now use this configuration
}

否则,您总是可以在需要时生成配置(或者有一个可以为您管理它的全局常量类)。

let realmURL = NSURL(string: "realm://example.com:9080/~/VWF3")!
let configuration = Realm.Configuration()
configuration.syncConfiguration = SyncConfiguration(user: SyncUser.current, realmURL: realmURL))
let realm = try! Realm(configuration: configuration)

关于ios - Realm 对象服务器创建数据库和 ROS 但不同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40917092/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com