【发布时间】:2018-07-23 22:18:22
【问题描述】:
我已经开始收到来自 Realm 的以下警告:
'init(user:realmURL:enableSSLValidation:isPartial:urlPrefix:)' 已弃用:改用 SyncUser.configuration()
我明白警告的意思,但我无法让SyncUser.configuration() 正常工作。这是我当前(已弃用)的实现:
if let _ = SyncUser.current {
// already logged in
let syncConfig = SyncConfiguration(user: SyncUser.current!, realmURL: Settings.Credentials.REALM_URL!)
let config = Realm.Configuration(syncConfiguration: syncConfig, objectTypes: [ConfigItem.self, Intersection.self])
self.database = try! Realm(configuration: config)
}
else {
let creds = SyncCredentials.usernamePassword(username: Settings.Credentials.REALM_LOGIN, password: Settings.Credentials.REALM_KEY)
SyncUser.logIn(with: creds, server: Settings.Credentials.AUTH_URL!, onCompletion: { [weak self](user, error) in
if let _ = user {
let syncConfig = SyncConfiguration(user: SyncUser.current!, realmURL: Settings.Credentials.REALM_URL!)
let config = Realm.Configuration(syncConfiguration: syncConfig, objectTypes: [ConfigItem.self, Intersection.self])
self?.database = try! Realm(configuration: config)
} else if let error = error {
fatalError(error.localizedDescription)
}
})
}
let syncConfig = ...... 这两行是我收到警告的地方。我可以让应用程序正确编译,像这样替换两个配置行:
let config = SyncUser.current!.configuration(realmURL: Settings.Credentials.REALM_URL!)
但是,这不允许我连接到我的同步领域。使用上述方法,也无法指定要同步的对象类型。有没有人从已弃用的SyncConfiguration 配置同步领域的方式迁移?它似乎应该接近我正在尝试的,但由于某种原因它没有连接。
编辑
如果我使用默认的SyncUser.configuration(),它至少会给我它连接到端点的消息,但数据不同步。这是使用默认同步配置的config:
let config = SyncUser.current!.configuration()
如果我重新添加 realmURL 参数,它不再给我连接到端点的消息。此外,不推荐使用的方法仍然是 https://realm.io/docs/swift/latest/#realms 文档中显示的内容:
// Create the configuration
let syncServerURL = URL(string: "realm://localhost:9080/~/userRealm")!
let config = Realm.Configuration(syncConfiguration: SyncConfiguration(user: user, realmURL: syncServerURL))
// Open the remote Realm
let realm = try! Realm(configuration: config)
【问题讨论】: