【问题标题】:How to get the date time the MongoDB Realm on client last synced?如何获取客户端上的 MongoDB Realm 上次同步的日期时间?
【发布时间】:2021-08-22 13:28:08
【问题描述】:

MongoDB Realm 后台同步数据,如何获取上次同步 Realm 的日期时间?希望向用户显示此信息以表明数据是最新的。

有一个 RLMSyncManager 类,但它似乎不包含有关上次同步的任何信息,https://docs.mongodb.com/realm-sdks/objc/latest/Classes/RLMSyncManager.html

【问题讨论】:

    标签: ios swift realm mongodb-realm


    【解决方案1】:

    领域SyncSession 对象有一个addProgressNotification 方法https://github.com/realm/realm-cocoa/blob/b606bfddaa0856489561727207e755659faa9a7e/RealmSwift/Sync.swift#L557,因此可以在那里添加一个回调来更新本地日期属性,以存储上次同步的领域更新时间。

    领域用户对象包含可通过user.allSessions 访问的活动会话列表,替代方法是realm.syncSession

            let realm = realmProvider.realm
    
            let progressTokenDownload = realm.syncSession?.addProgressNotification(
                for: .download,
                mode: .forCurrentlyOutstandingWork
            ) { progress in
                print(">>> DEBUG: [DCSettingsViewModel:checkRealmSyncingStatus] download", progress.fractionTransferred)
            }
    
            let progressTokenUpdate = realm.syncSession?.addProgressNotification(
                for: .upload,
                mode: .forCurrentlyOutstandingWork
            ) { progress in
                print(">>> DEBUG: [DCSettingsViewModel:checkRealmSyncingStatus] upload  ", progress.fractionTransferred)
            }
    
            if let progressTokenUpdate = progressTokenUpdate, let progressTokenDownload = progressTokenDownload {
                progressNotificationTokens.append(progressTokenUpdate)
                progressNotificationTokens.append(progressTokenDownload)
            }
    

    【讨论】:

      猜你喜欢
      • 2020-05-06
      • 2010-09-21
      • 2018-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多