Search code examples
realmrealm-mobile-platform

Check Realm Object Server Status in Swift


I want to be able to show an indicator in my Mac/iOS app if my Realm Object Server is offline.

As far as I can tell, the only available API is the Sync Session state.

I set up something like this after reading about the available states:

let session = SyncUser.current!.session(for: realmURL)!

if session.state.hashValue != 0{
  print("Offline or invalid")
}else{
  print("Online")
}

I then shut off my sync server, ran this code again, and it still said it was online. The state didn't seem to be accurate.

Is this supposed to work like this? Can I reliably determine the online/offline status of my ROS?


Solution

  • Unfortunately there's currently no way to determine whether your Realm Object Server is online or offline by using Realm's APIs.

    The reason you see the state reported as Active is because the session is still, from Realm's perspective, valid and connected. The underlying synchronization engine is responsible for handling failures in network connectivity, and does not currently expose this information to the binding layer (which is where this state variable lives).

    We know this is a frequently requested feature, and plan to build out something like it in the future.