【问题标题】:How to get the date time the MongoDB Realm on client last synced?如何获取客户端上的 MongoDB Realm 上次同步的日期时间?
【发布时间】:2021-08-22 13:28:08
【问题描述】:
【问题讨论】:
标签:
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)
}