Connection/sync status when using Atlas Device Sync with `RealmSwift`

Is there any way to check the current sync status when using Atlas Device Sync in Swift?
I’m looking for an ability to:

  • Wait for all pending synchronization tasks to finish
  • Show a connection status to the user (e.g. “Connected to Atlas”)
  • Show a sync status to the user (e.g. “Synchronizing”)
  • Show the date of the last synchronization to the user

I’m currently trying to determine the status using

syncSession.publisher(for: \.connectionState)

and

syncSession.addProgressNotification(for: .download, mode: .forCurrentlyOutstandingWork)

but that doesn’t seem to be reliable (the app sometimes incorrectly thinks it’s connected/synchronized).

Are you using Flexible Sync or Partition Based Sync? It’s worth noting that progress notifications are not supported in Flexible Sync yet, but this is coming soon.

You can check the connected state of the session by creating an observer: https://www.mongodb.com/docs/realm/sdk/swift/sync/network-connection/

I’m currently using partition-based sync.

As mentioned, observing the sync session’s \.connectionState unfortunately isn’t perfect.