updatedAt
属性,以便在离线设备具有更改时手动检查其是否具有更改。我还考虑在每个Core Data对象上拥有updatedLocally
和updatedOnline
时间戳属性。这样,如果两者不匹配,我可以进行差异检查并对冲突使用最近的一个,但这仍然不是最简洁的解决方案。 有其他人遇到类似的情况吗?如果是,你是怎么解决的?for every contact in parse database as onlineContact {
if onlineContact does not exist in core data {
create contact in core data
}
else {
// found matching local object to online object, check for changes
var localContact = core data contact with same UID as onlineContact
if localContact.offlineUpdate more recent than onlineContact.onlineUpdate {
for every attribute in localContact as attribute {
var lastOnlineValueReceived = Parse database Contact History at the time localContact.onlineUpdate for attribute
if lastOnlineValueReceived == localContact.attribute {
// this attribute did not change in the offline update. use latest available online value
localContact.attribute = onlineContact.attribute
}
else{
// this attribute changed during the more recent offline update, update it online
onlineContact.attribute = localContact.attribute
}
}
}
else if onlineContact.onlineUpdate more recent than localContact.offlineUpdate {
// another device updated the contact. use the online contact.
localContact = offlineContact
}
else{
// when a device is connected to the internet, and it saves a contact
// the offline/online update times are the same
// therefore contacts should be equivalent in this else statement
// do nothing
}
}
TL;DR: 您应该如何构建一种在线/离线更新的版本控制系统,以避免意外覆盖?我想将带宽使用限制到最低。
JSON
?解析提供了一个易于操作的PFObject
。 - Josue Espinosa