如何获取客户端上的 MongoDB 领域上次同步的日期时间?
How to get the date time the MongoDB Realm on client last synced?
MongoDB Realm在后台同步数据,如何获取realm上次同步的日期时间?想要向用户显示此信息以指示数据是最新的。
有一个 RLMSyncManager class 但它似乎不包含有关上次同步的任何信息,https://docs.mongodb.com/realm-sdks/objc/latest/Classes/RLMSyncManager.html
Realm SyncSession
对象有一个 addProgressNotification
方法 https://github.com/realm/realm-cocoa/blob/b606bfddaa0856489561727207e755659faa9a7e/RealmSwift/Sync.swift#L557 因此可以在其中添加回调以更新本地日期 属性 以存储最后同步的领域更新时间.
Realm 用户对象包含可通过 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)
}
MongoDB Realm在后台同步数据,如何获取realm上次同步的日期时间?想要向用户显示此信息以指示数据是最新的。
有一个 RLMSyncManager class 但它似乎不包含有关上次同步的任何信息,https://docs.mongodb.com/realm-sdks/objc/latest/Classes/RLMSyncManager.html
Realm SyncSession
对象有一个 addProgressNotification
方法 https://github.com/realm/realm-cocoa/blob/b606bfddaa0856489561727207e755659faa9a7e/RealmSwift/Sync.swift#L557 因此可以在其中添加回调以更新本地日期 属性 以存储最后同步的领域更新时间.
Realm 用户对象包含可通过 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)
}