SwiftUI how to retry @AsyncOpen when internet is restored ResolvedFailed error when offline

How do I sync the realm again once internet connection is restored?


  • User opens the app in the subway with no internet
  • “ResolvedFailed” error occurs
  • User exists the subway and internet is restored

I know the user can hard-close the app and re-open, but it’s bad user experience. Is there a better way?

Here’s a code sample:

struct MyApp: SwiftUI.App {
    let app: RealmSwift.App? = RealmSwift.App(id: YOUR_APP_SERVICES_APP_ID_HERE)
    var body: some Scene {
        WindowGroup {
            Group {
                if let app = app, let user = app.currentUser, let config = user.flexibleSyncConfiguration(initialSubscriptions: { subs in INITIAL_SUBSCRIPTION_WORK}, rerunOnOpen: true) {
                        .environment(\.realmConfiguration, config)
                } else {

struct OpenSyncedRealmView: View {
    @AsyncOpen(appId: my_app_id, timeout: 10000) var asyncOpen
    var body: some View {
        switch asyncOpen {
        case .error(let error):
                Text(error.localizedDescription) // This is "ResolvedFailed" when user is in subway (or on flight mode)
        case .connecting, .waitingForUser, .progress:
        case .open(let realm):
                .environment(\.realm, realm)