我开始从 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
配置同步领域的方法?看起来它应该接近我正在尝试的内容,但由于某种原因它没有连接。
EDIT
如果我使用默认的SyncUser.configuration()
,它至少会给我它已连接到端点的消息,但数据不同步。这里是config
使用默认同步配置:
let config = SyncUser.current!.configuration()
如果我添加realmURL
参数回来,它不再给我连接到端点消息。此外,已弃用的方法仍然是文档中显示的方法https://realm.io/docs/swift/latest/#realms 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)