简体   繁体   中英

Realm Object Server creating DB and ROS but not syncing

I have set up a Realm Object Server on AWS (RHAT) and it appears to be working fine. I can look at the dashboard which tells me how many connections, and how many realms open on port 9080. My code is working fine on the device, updates are happening on the devices realm. But I dont see anything changing in the ROS realm. I may be getting something very basic wrong, but I can't tell what.

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
        }
    })
}

I call setupRealm() from ViewDidLoad.

My developers need to be able to see the changes to the ROS realm to ensure all is working correctly, but all that is there is the single users realm, structure of tables is accurate, zero data.

I checked the log files on the server and nothing stood out.

Matt

You need to make sure you're still referring to that particular Realm (and its sync configuration) when doing your writes. If you tried to do a write to let realm = try! Realm() let realm = try! Realm() even after this login, you'd still be referencing your default Realm, which isn't synchronized.

If you plan to make your entire app synchronized, you can set that particular Configuration as your default Realm's one:

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
}

Otherwise you can always just generate the configuration when you need it (Or have a global constants class that can manage it for you).

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM