本文介绍了SyncConfiguration已弃用,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参数,它将不再给出Connected to Endpoint消息。此外,文档中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)

推荐答案

let config = SyncUser.current!.configuration(realmURL: url, fullSynchronization: false, enableSSLValidation: true, urlPrefix: nil)

我从他们的客户支持获得此链接:https://realm.io/docs/swift/3.7.5/api/Extensions/SyncUser.html#/s:So11RLMSyncUserC10RealmSwiftE13configurationAC0C0C13ConfigurationV10Foundation3URLVSg05realmH0_Sb19fullSynchronizationSb19enableSSLValidationSSSg9urlPrefixtF

这篇关于SyncConfiguration已弃用,SyncUser.configuration()的正确用法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-19 05:43